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