I am trying to make a function that multiplies 2 matrices into a new one , its almost finished but I am having had a hard time trying to figure out whats wrong with this line
Here's the Code:
#include<stdio.h>
#include<stdlib.h>
#define ROWS_1 3
#define ROWS_2 3
#define COLS_1 3
#define COLS_2 2
int* matrixMultiply(int mat1[ROWS_1][COLS_1],int mat2[ROWS_2][COLS_2])
{
int mul = (ROWS_1)*(COLS_2);
int* ArrofRows;
int sum=0,i,j,k;
***ArrofRows = (int*)malloc(mul)*sizeof(int);***
if (COLS_1 != ROWS_2)
{
printf("ERROR!! Operation Failed!Exiting...\n");
exit(0);
}
else
{
for( i=0 ; i<ROWS_1 ; i++)
{
for( j=0 ; j<COLS_2 ; j++)
{
for( k=0 ; k<COLS_1 ; k++)
{
sum += (mat1[i][k]*mat2[k][j]);
}
ArrofRows[(i*ROWS_1)+j] = sum;
sum = 0;
}
}
}
}
void main()
{
int mat1[ROWS_1][COLS_1] = {{2,6,9},{3,5,4},{6,7,8}};
int mat2[ROWS_2][COLS_2] = {{2,4},{6,1},{4,8}};
int* NewMat;
NewMat = matrixMultiply(mat1,mat2);
}