Introduction to 2-D Array's
#include <iostream>
using namespace std;
int main(){
int a[100][100];
int m,n ;
cout << "Enter no. of rows : " ;
cin >> m ;
cout << "Enter no. of columns : " ;
cin >> n ;
cout << "Enter elements : " ;
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j] ;
}
}
// Printing the given input
// 1) Rowwise
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
cout << a[i][j] << " " ;
}
cout << '\n';
}
// 2) Columnwise
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cout << a[j][i] << " ";
}
cout << '\n' ;
}
return 0 ;
}
Comments
Post a Comment