Array Exercises
Array Exercises
The exercises below are based upon the following declarations/initializations. ( You may
assume that each exercise starts with freshly initialized arrays. )
int table[ 5 ] [ 6 ] = { { 1, 2, 3, 4, 5 },
{ 2, 4, 6, 8, 10 },
{ 20, 10, 5, 3, 1 },
{ 3, 6, 9, 12, 15 } };
1. Write the code ( executable statements ) to fill the array square with the identity matrix.
16
25
10
20
40
80
4. Write the code to fill the array square as shown:
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
5. The partially initialized array "table" can be viewed as a primitive spreadsheet, in which the
last column and bottom row have been left blank. Write the code to fill in this row and
column with the totals of each column, each row, and the grand total.
1 2 3 4 5
2 4 6 8 10
20 10 5 3 1
3 6 9 12 15
6. Write the code to calculate the product of "square" times "table" and put the result in
"product".