Tutor Chetan
C Programming Language
Question: Addition and Subtraction of Two Matrix
/* Addition and Subtraction of two matrix */
/* Program Coded By Chetan Thapa Magar */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int m, n, i, j, a[10][10], b[10][10], add[10][10], sub[10][10];
printf("Enter the numbers for rows:\t");
scanf("%d", &m);
printf("\nEnter the number of columns:\t");
scanf("%d", &n);
printf("\nEnter the element of matrix A:\n");
for(i=0; i<m; i++)
for(j=0; j<n; j++)
scanf("%d", &a[i][j]);
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("\nThe Addition of Two Matrix is:\n");
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
add[i][j]=a[i][j]+b[i][j];
printf("%d\t", add[i][j]);
}
printf("\n");
}
printf("\nThe Subtraction of Two Matrix is:\n");
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
sub[i][j]=a[i][j]-b[i][j];
printf("%d\t", sub[i][j]);
}
printf("\n");
}
getch();
}
Output / Execution:
Enter the number of rows: 3
Enter the number of columns: 3
Enter the elements of matrix A:
1
2
3
4
5
6
7
8
9
Enter the elements of matrix B:
9
8
7
6
5
4
3
2
1
The Addition of Two Matrix is:
10 10 10
10 10 10
10 10 10
The Subtraction of Two Matrix is:
-8 -6 -4
-2 0 2
4 6 8
0 Comments