0% found this document useful (0 votes)
17 views

Array Exercises

Exercises for Array in C programming

Uploaded by

Tuan Ngo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Array Exercises

Exercises for Array in C programming

Uploaded by

Tuan Ngo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C Programming Array Exercises

The exercises below are based upon the following declarations/initializations. ( You may
assume that each exercise starts with freshly initialized arrays. )

int square[ 5 ][ 5 ] = { 0 }, product[ 5 ][ 6 ];

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.

2. Write the code to fill the array square as shown:

16

25

3. Write the code to fill the array square as shown:

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".

You might also like