I know there are multiple threads on Matrix Multiplication but all of them are either different from what i need, or are unanswered. I am trying to multiply two N x N matrices. The two matrices and N are all found in a file via argv[1].
I have spent hours and hours trying to get my code to compile and it finally does. then i ran the program and much to my dissapointment it just output hundreds and hundreds of numbers.
heres my code:
#include <stdio.h>
void MatrixMult(int x[][50], int y[][50], int z[][50], int *n);
int main(int argc, char *argv[]){
FILE *fin = fopen(argv[1], "r");
int i, j, n = fgetc(fin), x[n][n], y[n][n], z[n][n];
for(i = 0; i < n; i++)
for(j = 0; j < n; j++){
x[i][j] = fgetc(fin);
printf("%d", x[i][j]);
}
for(i = 0; i < n; i++)
for(j = 0; j < n; j++) y[i][j] = fgetc(fin);
for(i = 0; i < n; i++)
for(j = 0; j < n; j++) z[i][j] = 0;
MatrixMult( x, y, z, &n );
for(i = 0; i < n; i++){
for(j = 0; j < n; j++) printf(" %d", z[i][j]);
printf("\n");
}
return(0);
}
void MatrixMult(int x[][50], int y[][50], int z[][50], int *n ){
int i, j, k;
for(i = 0; i < *n; i++)
for(j = 0; j < *n; j++)
for(k = 0; k < *n; k++)
z[i][j] += x[i][k] * y[k][j];
return;
}