#include <stdio.h>
void input(int* r1, int* r2, int* c1, int* c2,
int arr1[*r1][*c1], int arr2[*r2][*c2]);
void matrix_multiply(int* r1, int* r2, int* c1, int* c2,
int arr1[*r1][*c1], int arr2[*r2][*c2], int result[50][50]);
int ouput_matrix(int*r1 , int* c2, int result[50][50]);
int main(void)
{
int arr1_out[50][50];
int arr2_out[50][50];
int result_out[50][50];
int a = 0;
int* r1 = &a;
int b = 0;
int* r2 = &b;
int c = 0;
int* c1 = &c;
int d = 0;
int* c2 = &d;
input(r1,r2,c1,c2,arr1_out,arr2_out);
matrix_multiply(r1, r2,c1, c2,arr1_out, arr2_out,result_out);
output_matrix(r1,c2,result_out);
}
void input(int* r1,int* r2,int* c1,int* c2,int arr1[*r1][*c1],int arr2[*r2][*c2])
{
printf("Enter the no. of rows and columns of first matrix ");
scanf("%d %d\n",r1,c1);
printf("Enter the no. of rows and columns of second matrix");
scanf("%d %d\n",r2,c2);
while(*c1 != *r2)
{
printf("Matrix cannot be multiplied...no. of columns of 1st matrix not equal to no. of rows of 2nd matrix");
printf("Enter the no. of rows and columns of first matrix ");
scanf("%d %d\n",r1,c1);
printf("Enter the no. of rows and columns of second matrix");
scanf("%d %d\n",r2,c2);
}
printf("Enter the elements of matrix 1");
for(int i = 0;i < *r1;i ++)
for(int j = 0;j < *c1;j ++)
{
printf("Enter element a%d%d",i + 1,j + 1);
scanf("%d",&arr1[i][j]);
}
printf("Enter the elements of matrix 2");
for(int i = 0;i < *r2;i ++)
for(int j = 0;j < *c2;j ++)
{
printf("Enter element b%d%d",i + 1,j + 1);
scanf("%d",&arr2[i][j]);
}
}
void matrix_multiply(int* r1,int* r2,int* c1,int* c2,int arr1[*r1][*c1],int
arr2[*r2][*c2],int result[50][50])
{
for(int i = 0; i < *r1; ++i)
for(int j = 0; j < *c2; ++j)
{
result[i][j] = 0;
}
for(int i = 0; i < *r1; ++i)
for(int j=0; j < *c2; ++j)
for(int k=0; k < *c1; ++k)
{
result[i][j]+=arr1[i][k]*arr2[k][j];
}
}
int ouput_matrix(int*r1 , int* c2, int result[50][50])
{
printf("\nOutput Matrix:\n");
for(int i = 0; i < *r1; ++i)
for(int j = 0; j < *c2; ++j)
{
printf("%d ", result[i][j]);
if(j == *c2-1)
printf("\n\n");
}
return 0;
}
Errors:
matrix_multi.c:32:53: runtime error: variable length array bound evaluates to non-positive value 0
matrix_multi.c:32:58: runtime error: variable length array bound evaluates to non-positive value 0
matrix_multi.c:32:72: runtime error: variable length array bound evaluates to non-positive value 0
matrix_multi.c:32:77: runtime error: variable length array bound evaluates to non-positive value 0