/************************************************************** * program: matrix_add.c * * description: matrix addition * * author: Mark Allen Weiss * (http://www.cs.fiu.edu/~weiss/dsaa_c2e/files.html) * modified by: Phil White **************************************************************/ #include typedef int Matrix[ 2 ][ 2 ]; /* Standard matrix multiplication */ /* Arrays start at 0 */ void MatrixAdd( Matrix A, Matrix B, Matrix C, int N ) { int i, j; for( i = 0; i < N; i++ ){ for( j = 0; j < N; j++ ){ C[ i ][ j ] = A[ i ][ j ] + B[ i ][ j ]; } } } int main(int argc, char *argv[] ) { Matrix A = { { 1, 2 }, { 3, 4 } }; Matrix B = { { 9, 5 }, { 8, 11 } }; Matrix C; MatrixAdd( A, B, C, 2 ); // Note you should make sure the 4 locations of the matrix // are someplace that I can see it in your trace printf( "%6x %6x\n%6x %6x\n", C[ 0 ][ 0 ], C[ 0 ][ 1 ], C[ 1 ][ 0 ], C[ 1 ][ 1 ] ); return 0; }