#include<stdio.h
void store(int x[4][4],int m,int n);
void add(int x[4][4],int y[4][4],int z[4][4],int m,int n);
void display(int x[4][4],int m,int n);
int main(void)
{
int a[4][4],b[4][4],c[4][4],m,n,p,q;
printf("enter the rows and cols of a matrix (A):\n");
scanf("%d%d",&m,&n);
printf("enter the rows and cols of matrix (B):\n");
scanf("%d%d",&p,&q);
if((m==p)&(n==q))
{
printf("enter the values in matrix(A):\n");
store(a,m,n);
printf("enter the values in matrix(B):\n");
store(b,p,q);
add(a,b,c,m,n);
printf("elements in matrix A is:\n");
display(a,m,n);
printf("elements in matrix B is:\n");
display(b,p,q);
printf("the addition of two matrix(A) and (B) is:\n");
display(c,m,n);
}
else
printf("addition not possible");
return 0;
}
void store(int x[4][4],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&x[i][j]);
}
printf("\n");
}
}
void add(int x[4][4],int y[4][4],int z[4][4],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
z[i][j]=x[i][j]+y[i][j];
}
}
}
void display(int x[4][4],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d ",x[i][j]);
}
printf("\n");
}
}
Multy
#include<stdio.h
void store(int x[4][4],int m,int n);
void mul(int x[4][4],int y[4][4],int z[4][4],int m,int p,int q);
void display(int x[4][4],int m,int n);
int main(void)
{
int a[4][4],b[4][4],c[4][4],m,n,p,q;
printf("enter the rows and cols of a matrix (A):\n");
scanf("%d%d",&m,&n);
printf("enter the rows and cols of matrix (B):\n");
scanf("%d%d",&p,&q);
if(n==p)
{
printf("enter the values in matrix(A):\n");
store(a,m,n);
printf("enter the values in matrix(B):\n");
store(b,p,q);
mul(a,b,c,m,p,q);
printf("elements in matrix A is:\n");
display(a,m,n);
printf("elements in matrix B is:\n");
display(b,p,q);
printf("the multiplication of two matrix(A) and (B) is:\n");
display(c,m,n);
}
else
printf("addition not possible");
return 0;
}
void store(int x[4][4],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&x[i][j]);
}
printf("\n");
}
}
void mul(int x[4][4],int y[4][4],int z[4][4],int m,int p,int q)
{
int i,j,k,sum=0;
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
for (k = 0; k < p; k++)
{
sum = sum + x[i][k]*y[k][j];
}
z[i][j] = sum;
sum = 0;
}
}
}
void display(int x[4][4],int m,int n)
{
int i,j;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("%d\t",x[i][j]);
}
printf("\n");
}
}