This
c program subtraction two matrices i.e. compute the subtraction of two matrices
and then print it. Firstly user will be asked to enter the order of matrix
(number of rows and columns) and then two matrices. For example if the user
entered order as 2, 2 i.e. two rows and two columns and matrices as
First Matrix :-
First Matrix :-
4
5
8 5
Second matrix :-
1 2
3 4
then output of the program (sum of First and Second matrix) will be
3 3
8 5
Second matrix :-
1 2
3 4
then output of the program (sum of First and Second matrix) will be
3 3
5
1
#include
<stdio.h>
#include<conio.h>
void
main()
{
int m, n, c, d, first[10][10],
second[10][10], sum[10][10];
clrscr();
printf("Enter the number of rows and
columns of matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of first
matrix\n");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d",
&first[c][d]);
printf("Enter the elements of second
matrix\n");
for (c = 0; c < m; c++)
for (d = 0 ; d < n; d++)
scanf("%d",
&second[c][d]);
printf("Sum of entered
matrices:-\n");
for (c = 0; c < m; c++) {
for (d = 0 ; d < n; d++) {
sum[c][d] = first[c][d] - second[c][d];
printf("%d\t", sum[c][d]);
}
printf("\n");
}
getch();
}
No comments:
Post a Comment