/************(soeasyprograms.blogspot.in)*************/
/*A program to find sum of two matrices*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n,p,q;
clrscr();
printf("enter the order of A matrix");
printf("\nenter the number of rows: ");
scanf("%d",&m);
printf("\nenter the number of columns: ");
scanf("%d",&n);
printf("enter the order of B matrix");
printf("\nenter the number of rows: ");
scanf("%d",&p);
printf("\nenter the number of columns: ");
scanf("%d",&q);
if((m==p)&&(n==q))
{
printf("\nenter the elements of A: ");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n A matrix is:");
for(i=1;i<=m;i++)
{
printf("\n");
for(j=1;j<=n;j++)
{
printf(" %d",a[i][j]);
}
}
printf("\nenter the elements of B: ");
for(i=1;i<=p;i++)
{
for(j=1;j<=q;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n B matrix is:");
for(i=1;i<=p;i++)
{
printf("\n");
for(j=1;j<=q;j++)
{
printf(" %d",b[i][j]);
}
}
printf("\nsum of A & B is: ");
for(i=1;i<=m;i++)
{
printf("\n");
for(j=1;j<=n;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf(" %d",c[i][j]);
}
}
}
else
{
printf("\nenter both matrix of the same order");
}
getch();
}
/************(soeasyprograms.blogspot.in)*************/
No comments:
Post a Comment