# Thread: sum and product of two matrix in C (with functions)

1. ## sum and product of two matrix in C (with functions)

I have to write a program in C which finds the sum and the product of two matrix.
I wrote the functions but I get stucked at calling them in main .I don't know which variable is for rows and columns of result matrix.

Code:

Code:
```#include <stdio.h>
void enterMatrix(int a[][10], int rows, int columns)
{
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
printf("a(%d,%d)=",i,j);
scanf("%d",&a[i][j]);
}
}
}
void displayMatrix(int a[][10], int rows, int columns)
{
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
printf("%d", a[i][j]);
printf(" ");
}
printf("\n");
}
}
void matrixSum(int a[][10], int b[][10], int c[][10], int rows, int columns)
{
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
}
void matrixProduct(int a[][10], int b[][10], int c[][10], int rows, int columns)
{
int i,j,k;
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
c[i][j]=0;
for(k=0;k<columns;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}

}
}
}
int main(void)
{
int a[10][10], b[10][10], sum[10][10], product[10][10];
int rowsA,columnsA,rowsB,columnsB;
printf("Number of rows for matrix A: \n");
scanf("%d",&rowsA);
printf("Number of columns for matrix A: \n");
scanf("%d",&columnsA);
printf("Number of rows for matrix B: \n");
scanf("%d",&rowsB);
printf("Number of columns for matrix B: \n");
scanf("%d",&columnsB);
printf("Enter first matrix: \n");
enterMatrix(a,rowsA,columnsA);
printf("Show first matrix: \n");
displayMatrix(a,rowsA,columnsA);
printf("Enter second matrix: \n");
enterMatrix(b,rowsB,columnsB);
printf("Show second matrix: \n");
displayMatrix(b,rowsB,columnsB);

if((rowsA==rowsB) && (columnsA==columnsB))
{
matrixSum(a,b,sum, ???, ???);
printf("The sum matrix is: \n");
displayMatrix(sum, ???, ???);
}
else
{
printf("Wrong information.");
}
if((rowsA==columnsB) && (rowsB==columnsA))
{
matrixProduct(a,b,product,???,???);
printf("The product matrix is \n");
displayMatrix(product,???,???);
}
return 0;
}```

2. > .I don't know which variable is for rows and columns of result matrix.
...
> if((rowsA==rowsB) && (columnsA==columnsB))
But if they're the same, does it matter?

matrixSum(a,b,sum, rowsA, columnsA);
is exactly the same as
matrixSum(a,b,sum, rowsB, columnsB);