#include<stdio.h>
main()
{
int a[100][100],b[100][100],sum[100][100],r1,c1,r2,c2,i,j;
printf("\nEnter row number of the 1st matrix=");
scanf("%d",&r1);
printf("\nEnter column number of the 1st matrix=");
scanf("%d",&c1);
printf("\nEnter the 1st matrix elements=");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nThe 1st matrix is\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%6d",a[i][j]);
}
printf("\n");
}
printf("\nEnter row number of the 2nd matrix=");
scanf("%d",&r2);
printf("\nEnter column number of the 2nd matrix=");
scanf("%d",&c2);
printf("\nEnter the 2nd matrix elements=");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\nThe 2nd matrix is\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%6d",b[i][j]);
}
printf("\n");
}
if(r1!=r2 ||c1!=c2)
printf("\nMatrix addition is not possible\n");
else
{
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
sum[i][j]=a[i][j]+b[i][j];
}
}
printf("\nThe sum matrix is\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%6d",sum[i][j]);
}
printf("\n");
}
}
}
main()
{
int a[100][100],b[100][100],sum[100][100],r1,c1,r2,c2,i,j;
printf("\nEnter row number of the 1st matrix=");
scanf("%d",&r1);
printf("\nEnter column number of the 1st matrix=");
scanf("%d",&c1);
printf("\nEnter the 1st matrix elements=");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nThe 1st matrix is\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%6d",a[i][j]);
}
printf("\n");
}
printf("\nEnter row number of the 2nd matrix=");
scanf("%d",&r2);
printf("\nEnter column number of the 2nd matrix=");
scanf("%d",&c2);
printf("\nEnter the 2nd matrix elements=");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\nThe 2nd matrix is\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%6d",b[i][j]);
}
printf("\n");
}
if(r1!=r2 ||c1!=c2)
printf("\nMatrix addition is not possible\n");
else
{
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
sum[i][j]=a[i][j]+b[i][j];
}
}
printf("\nThe sum matrix is\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%6d",sum[i][j]);
}
printf("\n");
}
}
}
No comments:
Post a Comment