hi all..i hope every1 is fine... my teacher gav me this assignment and i m stuck... i cant seem to get the right answer..i hav spent hours but no useplz see the code...
Its a simple matrix multiplication program. There are 3 matrices in the program m1,m2,m3...m1 and m2 are multiplied and m3 is assignmed the result...
m1=| 2 1 6 |
| 5 4 0 |
m2=| 5 1 |
| 9 7 |
| 6 2 |
The result has to be:
m3=| 55 21 |
| 61 33 |
but i m getting something else! i m getting: 55 55,33 29
m3=| 55 55 |
| 33 29 |
Here is the code:
Any help is highly appreciated... thanks in advance...Code:#include <stdio.h> #include <conio.h> void main(void) { int m1[2][3], m2[3][2], m3[2][2], i, j, k; clrscr(); printf("First Matrix\n"); printf("============\n"); // populate the first matrix for (i=0; i<2; i++) { for (j=0; j<3; j++) { printf("Enter value for position [%d][%d]: ",i,j); scanf("%d", &m1[i][j]); } } printf("\nSecond Matrix\n"); printf("=================\n"); // populate the second matrix for (i=0; i<3; i++) { for (j=0; j<2; j++) { printf("Enter value for position [%d][%d]:",i,j); scanf("%d",&m2[i][j]); } } printf("\nMatrix Multiplication\n"); printf("=====================\n"); for (i=0; i<2; i++) { for (j=0; j<2; j++) { for (k=0; k<2; k++) { m3[i][j] = (m1[i][j]*m2[j][i])+(m1[i][j+1]*m2[j+1][i])+(m1[i][j+2]*m2[j+2][i]); } } } // print the m3 matrix for (i=0; i<2; i++) { for (j=0; j<2; j++) { printf("\nValue at position [%d][%d] is: %d",i,j,m3[i][j]); } } getch(); }
regards,
Kamran.



LinkBack URL
About LinkBacks
plz see the code...



i m still on it... and if i cant do it by tonite, then i'll ask any of the senior students at my UNI... coz exams are not far so i hav to practice it as well...