COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
array2D.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3using namespace std;
4
5
6
7int main()
8{
9 const int nRows = 3;
10 const int nCols = 5;
11
12 int array2D[nRows][nCols];
13 int i, j;
14
15 // assign initial values
16 for (i = 0; i < nRows; ++i)
17 for (j = 0; j < nCols; ++j)
18 array2D[i][j] = nCols*i + j;
19
20 // print out array contents
21 for (i = 0; i < nRows; ++i)
22 {
23 for (j = 0; j < nCols; ++j)
24 cout << setw(3) << array2D[i][j] << ' ';
25 cout << endl; // start new line for each row
26 }
27
28 return 0;
29}
30
int main()
Definition array2D.cpp:7