[I don't understand why z4][4] = ... (in the imange) I want to code a program that can make matrices multiplication but when I run my code with two 2x2 matrices, my output z[1][1], z[1][2], z[2][1] is the same that I expected (value), only z[2][2] is printed with its address. I have tried with bigger matrices, my bug happened with more entry. Can someone help me.
#include <stdio.h>
int main() {
const int m,n,k;
scanf("%d %d %d",&m,&n,&k); // size of 3 matrices
int a[m][n];
int b[n][k];
int z[m][k];
int i,j,e,r,v,x,c;
for (i=1;i<=m;i++){ // declare matrix a
for (j=1;j<=n;j++){
scanf("%d",&a[i][j]);
}
}
for (e=1;e<=n;e++){ // declare matrix b
for(r=1;r<=k;r++){
scanf("%d",&b[e][r]);
}
}
for (c=1;c<=m;c++){ // multipication of a and b
for (v=1;v<=k;v++){
for (x=1;x<=n;x++){
z[c][v]+=a[c][x]*b[x][v];
}
printf("%d ",z[c][v]);
x=1;
}
v=1;
printf("\n");
}
return 0;
}