Can anyone please debug this simple program of mine. It takes two 3*3 matrices and multiplies them. Everything is right, except that when the 2nd matrix gets printed, the first element is printed as a muliple of 4. I can't find anything wrong.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3]={0,0,0,0,0,0,0,0,0};
int j,i,x,y; clrscr();
x=y=0;
for(i=0;i<=2;i++) /* Initialize 1st Matrix */
for(j=0;j<=2;j++)
scanf("%d",&a[i][j]);
for(i=0;i<=2;i++) /* Initialize 2nd Matrix */
for(j=0;j<=2;j++)
scanf("%d",&b[i][j]);
for(;x<=2;y++)
{ if(y==3)
{x++; y=0;} /* Multiply the two matrices and store them in c */
for(j=0;j<=2;j++)
{
c[x][y]+=(a[x][j]*b[j][y]);
}
}
printf("\n1st Matrix\n"); /* Print 1st Matrix */
for(i=0;i<=2;i++)
{ for(j=0;j<=2;j++)
printf("%d ",a[i][j]);
printf("\n");
}
printf("\n2nd Matrix\n"); /* Print 2nd Matrix */
for(i=0;i<=2;i++)
{ for(j=0;j<=2;j++)
printf("%d ",b[i][j]);
printf("\n");
}
printf("\nFinal Matrix\n"); /* Print Multiplied Matrix */
for(i=0;i<=2;i++)
{ for(j=0;j<=2;j++)
printf("%d ",c[i][j]);
printf("\n");
}
}