Write a program to read two matrices A and B and print the following:
(a) A + B; and
(b) A - B.
#include <stdio.h>
main()
{
int A[50][50],B[50][50],i,j,r,c;
clrscr();
printf("Enter No. of Rows of Matrix:");
scanf("%d",&r);
printf("Enter No. of Column of Matrix:");
scanf("%d",&c);
printf("Enter the elements of Matrix A\n");
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf("%d",&A[i][j]);
printf("Enter the elements of Matrix B\n");
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf("%d",&B[i][j]);
printf("SUM OF MATRIX A AND B\n");
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
printf("%3d",A[i][j]+B[i][j]);
putchar('\n');
}
printf("MATRIX A - MATRIX B\n");
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
printf("%3d",A[i][j]-B[i][j]);
putchar('\n');
}
getch();
}
(a) A + B; and
(b) A - B.
#include <stdio.h>
main()
{
int A[50][50],B[50][50],i,j,r,c;
clrscr();
printf("Enter No. of Rows of Matrix:");
scanf("%d",&r);
printf("Enter No. of Column of Matrix:");
scanf("%d",&c);
printf("Enter the elements of Matrix A\n");
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf("%d",&A[i][j]);
printf("Enter the elements of Matrix B\n");
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf("%d",&B[i][j]);
printf("SUM OF MATRIX A AND B\n");
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
printf("%3d",A[i][j]+B[i][j]);
putchar('\n');
}
printf("MATRIX A - MATRIX B\n");
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
printf("%3d",A[i][j]-B[i][j]);
putchar('\n');
}
getch();
}

No comments:
Post a Comment