I've written a procedure, that creates 2 matrices and multiplies them. However I have to divide my code into functions, and I have a problem with declaring a function that will allocate the memory for matrices.
Here's my code:
void matrixMult(){
int **A, **B, **C; //matrices
int rowA, colA, rowB, colB; //rows and columns
int i, j, k; //for iterations
printf("Number of rows in matrix A: \n");
scanf("%d", &rowA);
printf("Number of columns in matrix A: \n");
scanf("%d", &colA);
printf("Number of rows in matrix B: \n");
scanf("%d", &rowB);
printf("Number of columns in matrix B: \n");
scanf("%d", &colB);
//memory allocation
A = (int**)malloc(rowA * sizeof(int));
B = (int**)malloc(rowB * sizeof(int));
C = (int**)malloc(rowA * sizeof(int));
for (i = 0; i < rowA; i++)
{
A[i] = (int*)malloc(colA * sizeof(int));
}
for (i = 0; i < rowB; i++)
{
B[i] = (int*)malloc(colB * sizeof(int));
}
for (i = 0; i < rowA; i++)
{
C[i] = (int*)malloc(colB * sizeof(int));
}
/*
the rest of code
*/
}
What should this function look like?