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
|
#include <iostream>
using namespace std;
int main()
{
// 2 dimensional array, 4 rows by 5 columns
int s[4][5] =
{
{1, 2, 3, 4, 17},
{5, 6, 7, 8, 18},
{9, 10, 11, 12, 19},
{13, 14, 15, 16, 20}
};
// 2 dimensional array 3 rows by 3 columns compiler figures out number of rows based on initialisation
int s2[][3] =
{
{9, 8, 6},
{7, 9, 5},
{4, 3, 2}
};
// Print row 2 (3rd row) of array s
for (int i = 0; i < 5; ++i)
cout << s[2][i] << " ";
cout << endl << endl;
// print column 0 (1st column) of s2
for (int i = 0; i < 3; ++i)
cout << s2[i][0] << endl;
}
|