I have written this, but it doesn't work :( I want the array to be displayed in a table with 3 rows and 5 columns.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
constint r=5;
constint c=3;
int myarray[r][c];
for (r=0;r<5;r++)
for (c=0;c<3;c++)
{
cin>>myarray[r][c];
}
for (r=0;r<3;r++)
for (c=0;c<5;c++)
{
cout<<myarray[r][c];
}
It wont do any good if you only invert the loops, you also have to invert the indices.
Also, you can't change the values of constants dude, so you need different variables for the counters.
#include <iostream>
usingnamespace std;
constint R=5;
constint C=3;
int main() {
int r, c;
int myarray[R][C];
for (r=0; r<R; r++)
for (c=0;c<C;c++)
cin >> myarray[r][c];
for (c=0;c<C;c++) {
for (r=0;r<R;r++)
cout << myarray[c][r] << endl;
cout << endl; // it's no table if you don't insert new lines
}
return 0;
}