COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
array2D.cpp File Reference
#include <iostream>
#include <iomanip>
Include dependency graph for array2D.cpp:

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( void )

Definition at line 7 of file array2D.cpp.

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}