-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerate-array-and-display-with-diagonal.cpp
More file actions
62 lines (46 loc) · 1.18 KB
/
Generate-array-and-display-with-diagonal.cpp
File metadata and controls
62 lines (46 loc) · 1.18 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//CSC 160 Quiz 3 part B 2
//Purpose: Write program for three functions with array
//Author: Larsen J Close Most recent changes: 4/22/16
#include <iostream> // preprocessor directive
#include <iomanip> // needed for most manipulators
using namespace std; // using directive
const int M = 3;
void display(int y[][M])
{
for( int t = 0; t<M ; t++)
{
for( int u = 0; u<M; u++)
{
cout << setw(5) << y[t][u];
if( u == 2)
cout << endl;
}
}
}
void fill(int x[][M])
{
for( int n = 0; n<M; n++)
{
for(int m = 0; m<M; m++)
if( m == n)
x[n][m] = 1;
else
x[n][m] = 0;
}
}
int main ( void )
{
int z[M][M]; // create empty 2D array 3x3
fill(z);
cout << "\nDisplay of the z array\n";
display(z);
system("pause");
return 0;
} //end main ( )
/* Display of above program
Display of the z array
1 0 0
0 1 0
0 0 1
Press any key to continue . . .
*/