-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path23_2D_ArrayIntro.cpp
57 lines (47 loc) · 1.09 KB
/
23_2D_ArrayIntro.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;
int main()
{
int rows, cols;
cout << "Enter rows and cols:";
cin >> rows >> cols;
int arr[rows][cols];
cout << "Enter the matrix elements:";
// int arr2[3][4]={1,2,3,4,5,6,7,8,9,11,12,10};
// int arr3[3][4]={{1,11,111,1111},{2,22,222,2222},{3,33,333,3333}};
// Taking Input rows wise:
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cin >> arr[i][j];
}
}
// Taking Input column wise:
// for (int i = 0; i < cols; i++)
// {
// for (int j = 0; j < rows; j++)
// {
// cin>>arr[j][i];
// }
// }
// Print 2-D array:
// for (int i = 0; i < 3; i++)
// {
// for (int j = 0; j < 4; j++)
// {
// // cout<<arr2[i][j]<<" ";
// cout<<arr3[i][j]<<" ";
// }
// cout<<endl;
// }
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cout << arr[i][j] << " ";
}
cout << endl;
}
return 0;
}