PROGRAM TO FIND SUM OF TWO MATRICES

/*PROGRAM TO FIND SUM OF TWO MATRICES*/
#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,p,q,i,j,a[10][10],b[10][10],c[10][10];
clrscr();
printf(“Enter the order of first matrix: “);
scanf(“%d%d”,&m,&n);
printf(“Enter the order of second matrix: “);
scanf(“%d%d”,&p,&q);
if((m==p)&&(n==q))
{
printf(“Enter the %d elements of first matrix:\n”,m*n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf(“%d”,&a[i][j]);
}
printf(“Enter the %d elements of second matrix:\n”,p*q);
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
scanf(“%d”,&b[i][j]);
}
printf(“The first matrix of %d*%d order is:\n”,m,n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf(“%4d”,a[i][j]);
printf(“\n”);
}
printf(“The second matrix of %d*%d order is:\n”,p,q);
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
printf(“%4d”,b[i][j]);
printf(“\n”);
}
//ADDING TWO MATRICES
printf(“The %d*%d matrix obtained after addition of two matrices is:\n”,m,n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf(“%4d”,c[i][j]);
}
printf(“\n”);
}
}
else
printf(“Addition is not possible as the order of two matrices is not same.”);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *