Make a function to add two matrices
#include <stdio.h>
int matrix();
int main()
{
matrix(); //calling function
}
int matrix()
{
int a[10][10],b[10][10],add[10][10],p,q,i,j; //a=first matrix , b=second matrix , i & j conytolling loops
printf("Enter the order of the two matices\n");
scanf("%d%d" , &p , &q);
for(i=0; i<p; i++)
{
for(j=0; j<q; j++)
{
printf("Enter the entry for %d row and %d column for Ist matrix\n" , i+1 ,j+1);
scanf("%d" , &a[i][j]);
}
}
for(i=0; i<p; i++)
{
for(j=0; j<q; j++)
{
printf("Enter the value for %d row and %d column for 2nd matrix\n" ,i+1 , j+1);
scanf("%d" , &b[i][j]);
}
}
for(i=0; i<p; i++)
{
for(j=0; j<q; j++)
{
add[i][j]=a[i][j]+b[i][j];
}
}
printf("SUM of the matrices is \n");
for(i=0; i<p; i++)
{
for(j=0; j<q; j++)
{
printf("%d\t" , add[i][j]);
}
printf("\n");
}
return 0;
}
function to add two matrices in C |