0

C Program to subtract two matrices.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[5][5],b[5][5],m,n,sum;
clrscr();
printf(“Enter the number of rows and columns for matrices:(max 5)”);
scanf(“%d%d”,&m,&n);
printf(“Enter the elements of first matrix”);
for(i=0;i<m;i++)
{
 for(j=0;j<n;j++)
  {
   scanf(“%d”,&a[i][j]);
  }
}
printf(“Enter the elements of second matrix”);
for(i=0;i<m;i++)
{
 for(j=0;j<n;j++)
  {
   scanf(“%d”,&b[i][j]);
  }
}
printf(“\nOn addition we get…. \n”);
for(i=0;i<m;i++)
{ printf(“\n”);
 for(j=0;j<n;j++)
  {
   sum=b[i][j]+a[i][j];
   printf(”  %d”,sum);
   sum=0;
  }
  printf(“\n”);
}
getch();
}

ks007

Leave a Reply

Your email address will not be published. Required fields are marked *