I am trying to do some matrix multiplication but i keep getting a expected declaration at the end of input. Any help would be much appreciated.
Code:
/* Description:To multiply given to matrix using arrays*/ #include<stdio.h> #include<math.h> main() { int i,j,k; int a,b,c;/*three variables to get the row and colum of the two matrix*/ int sum; int m[5][5],n[5][5],l[5][5]; printf("The first matrix:\n"); printf("Enter the number of rows and columns for the first matrix:\t") ; scanf("%d%d",&a,&b); printf("The Second matrix:\n"); printf("Enter the rows and columns of the second matrix:\t"); scanf("%d%d",&b,&c); /* Note: For matrix multiplication the number of columns in the first matrix should be equal to the number of rows in the second message*/ printf(":Enter the values of the first matrix:\n"); for(i=0;i<a;i++) { for(j=0;j<b;j++) { scanf("%d",&m[i][j]); } } printf("Enter the values of the second matrix:\n"); for(i=0;i<b;i++) { for(j=0;j<c;j++) { scanf("%d",&n[i][j]); } } for(i=0;i<a;i++) { for(j=0;j<c;j++) { sum=0; for(k=0;k<b;k++) { sum=sum+(m[i][k]*n[k][j]); l[i][j]=sum; } } } printf("The multiplied matrix is:\n"); for(i=0;i<a;i++) { for(j=0;j<c;j++) { printf ("%d",l[i][j]); printf("\t"); } printf("\n"); }
Comment