-
Notifications
You must be signed in to change notification settings - Fork 4
/
fig10_38.c
34 lines (27 loc) · 848 Bytes
/
fig10_38.c
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
#include <stdio.h>
typedef double Matrix[ 2 ][ 2 ];
/* START: fig10_38.txt */
/* Standard matrix multiplication */
/* Arrays start at 0 */
void
MatrixMultiply( Matrix A, Matrix B, Matrix C, int N )
{
int i, j, k;
for( i = 0; i < N; i++ ) /* Initialization */
for( j = 0; j < N; j++ )
C[ i ][ j ] = 0.0;
for( i = 0; i < N; i++ )
for( j = 0; j < N; j++ )
for( k = 0; k < N; k++ )
C[ i ][ j ] += A[ i ][ k ] * B[ k ][ j ];
}
/* END */
main( )
{
Matrix A = { { 1, 2 }, { 3, 4 } };
Matrix C;
MatrixMultiply( A, A, C, 2 );
printf( "%6.2f %6.2f\n%6.2f %6.2f\n", C[ 0 ][ 0 ], C[ 0 ][ 1 ],
C[ 1 ][ 0 ], C[ 1 ][ 1 ] );
return 0;
}