C program to calculate subtraction of two matrices.

#include<stdio.h>
#include<conio.h>
#define r 2
#define c 2
void main(){
int a[r][c],b[r][c],sub[r][c],i,j;
clrscr();
printf("enter elements of matrix A\n");
for (i=0; i<r; i++){
for (j=0; j<c; j++){
printf("enter A[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}}
printf("enter elements of matrix B\n");
for (i=0; i<r; i++){
for (j=0; j<c; j++){
printf("enter B[%d][%d]=",i,j);
scanf("%d",&b[i][j]);
}}
for (i=0; i<r; i++){
for (j=0; j<c; j++){
sub[i][j]=a[i][j]-b[i][j];
}}
printf("Subtraction of A and B matrix is:\n"); 
for (i=0; i<r; i++){
for (j=0; j<c; j++){
printf("%d",sub[i][j]);
}
printf("\n");
}
getch(); 
}

No comments:

Post a Comment