I'm reading through "Illustrated C" and the first exercise question asks:
Program MATMUL multiplies matrices of fixed size. Make the program deal with any specified sizes.
So below is the code that I have come up with thus far. However I read that all attributes need to be declared before the main function. So how do I get custom sized arrays without declaring them in the main function?
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
int n, m, i, j, k;
int main(void)
{
printf("\nEnter:rows for A, columns for A and rows for B, columns for B\n");
scanf("%i %i %i", &i, &j, &k);
float A[i][j], B[j][k], C[i][k]; //Not legal, right?
/*Read in A array*/
for(n=0; n<i; ++n)
for(m=0; m<j; ++m)
scanf("%f", &A[n][m]);
/*Read in B array*/
for(n=0; n<j; ++n)
for(m=0; m<k; ++m)
scanf("%f", &B[n][m]);
/*Calculate C array*/
for(j=0; j<i; ++j)
for(i=0; i<k; ++i)
{
C[i][j] = 0;
for (k=0; k<j; ++k)
C[i][j] += A[i][k] * B[k][j];
}
for(n=0; n<i; ++n)
for(m=0; m<k; ++m)
printf("\n%.2f\t", C[n][m]);
return 0;
}