Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 41bc7fe

Browse files
convert 2d array to 1d array
1 parent aad46f3 commit 41bc7fe

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎Convert.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include<iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int n,m,i,j,k,count=0;
6+
cin>>n>>m;
7+
k=n*m;
8+
int arr1[n][m];
9+
int arr2[k];
10+
for(i=0;i<n;i++)
11+
{
12+
for(j=0;j<m;j++)
13+
{
14+
cin>>arr1[i][j];
15+
}
16+
}
17+
for(i=0;i<n;i++)
18+
{
19+
for(j=0;j<m;j++)
20+
{
21+
arr2[count++]=arr1[i][j];
22+
}
23+
}
24+
cout<<"Displaying 2D array\n";
25+
for(i=0;i<n;i++)
26+
{
27+
for(j=0;j<m;j++)
28+
{
29+
cout<<arr1[i][j]<<"\t";
30+
}
31+
cout<<"\n";
32+
}
33+
cout<<"Displaying 1D array\n";
34+
for(i=0;i<k;i++)
35+
{
36+
cout<<arr2[i]<<"\t";
37+
}
38+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /