/* Addition and subtraction of two matrices */
#include<stdio.h>
#include<math.h>
int main()
{
int i, j, n, m, a[20] [20], b[20] [20], c[20] [20], d[20] [20];
printf("Enter order of the matrices:\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of matrix A:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d", &a[i] [j]);
printf("\n");
}
printf("Entered Matrix A:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%10d",a[i] [j]);
printf("\n");
}
printf("\nEnter the elements of matrix B:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d", &b[i] [j]);
printf("\n");
}
printf("Entered Matrix B:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%10d",b[i] [j]);
printf("\n");
}
/* Matrix addition */
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
c[i] [j]=a[i] [j]+b[i] [j];
}
printf("Matrix sum C=A+B is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%10d\t", c[i] [j]);
printf("\n");
}
/* Matrix subtraction */
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
d[i] [j]=a[i] [j]-b[i] [j];
}
printf("Matrix subtraction D=A-B is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%10d\t", d[i] [j]);
printf("\n");
}
return(0);
}
#include<stdio.h>
#include<math.h>
int main()
{
int i, j, n, m, a[20] [20], b[20] [20], c[20] [20], d[20] [20];
printf("Enter order of the matrices:\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of matrix A:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d", &a[i] [j]);
printf("\n");
}
printf("Entered Matrix A:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%10d",a[i] [j]);
printf("\n");
}
printf("\nEnter the elements of matrix B:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d", &b[i] [j]);
printf("\n");
}
printf("Entered Matrix B:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%10d",b[i] [j]);
printf("\n");
}
/* Matrix addition */
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
c[i] [j]=a[i] [j]+b[i] [j];
}
printf("Matrix sum C=A+B is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%10d\t", c[i] [j]);
printf("\n");
}
/* Matrix subtraction */
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
d[i] [j]=a[i] [j]-b[i] [j];
}
printf("Matrix subtraction D=A-B is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%10d\t", d[i] [j]);
printf("\n");
}
return(0);
}
Comments
Post a Comment