EXERCISE C16
Write a C program incorporating a function to add all elements of
a two dimensional array. The number of rows are to be passed to
the function, and it passes back the total sum of all elements
(Use at least a 4 x 4 array).
#include <stdio.h>
int add2darray( int [][5], int ); /* function prototype */
int add2darray( int array[][5], int rows )
{
int total = 0, columns, row;
for( row = 0; row < rows; row++ )
for( columns = 0; columns < 5; columns++ )
total = total + array[row][columns];
return total;
}
main()
{
int numbers[][] = { {1, 2, 35, 7, 10}, {6, 7, 4, 1, 0} };
int sum;
sum = add2darray( numbers, 2 );
printf("the sum of numbers is %d\n", sum );
}