Page t028, go to NEXT,
PREVIOUS, INDEX
Example Code and Test
Multiplying matrices
float m[3][3], m1[3][3], m2[3][3];
double sum;
int i, j, k;
/* Code to initialize m1 and m2. */
/* Compute m = m1 * m2. */
for ( i = 0; i < 3; i++ )
{ for ( j = 0; j < 3; j++ )
{ sum = 0.0;
for ( k = 0; k < 3; k++ )
{ sum += m1[i][k] * m2[k][j];
}
m[i][j] = sum;
}
}
- If you understand this code, then you know enough C to code the
algorithmic part of your code.
- At the beginning of this session, the above code would probably
have been gibberish.
- If you can not understand this code, we are going too fast :-(
C Course, 21-jan-1997,
Peter Klok,
pfk@hef.kun.nl