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
|
#include <iostream>
using namespace std;
const int ROWS = 2;
const int COLS = 4;
int main()
{ int nums[ROWS][COLS] = { { 17, 24, 86, 35 },
{ 23, 36, 10, 12 } };
int row = 0;
int column = 0;
//display column by column
while (column < COLS)
{ cout << "\nColumn " << column + 1 << " : ";
for (int row = 0; row < ROWS; row++)
{ cout << nums[row][column];
if (row != ROWS-1)
cout << ", ";
}
column++;
}
cout << endl;
//display row by row
while (row < ROWS)
{ cout << "\nRow " << row + 1 << " : ";
for (column = 0; column < COLS; column++)
{ cout << nums[row][column];
if (column != COLS-1)
cout << ", ";
}
row++;
}
cout << endl;
system("pause");
return 0;
} //end of main function
|
Column 1 : 17, 23
Column 2 : 24, 36
Column 3 : 86, 10
Column 4 : 35, 12
Row 1 : 17, 24, 86, 35
Row 2 : 23, 36, 10, 12
Press any key to continue . . . |