Write a C program to perform the following:
i. Addition of two matrices
ii. Multiplication of two matrices
Program Code:
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],i,j,m,n,p,q;
printf(" enter row & column of Mat1\n");
scanf("%d%d",&m,&n);
printf(" enter row & column of Mat2\n");
scanf("%d%d",&p,&q);
if(m==p&&n==q)
{
printf(" enter Mat1\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf(" enter Mat2\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n sum of the matrices\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%8d",a[i][j]+b[i][j]);
}
printf("\n");
}
printf("\n difference of the matrices\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%8d",a[i][j]-b[i][j]);
}
printf("\n");
}
}
else
printf("\n operations not possible...");
}
Post A Comment:
0 comments: