Subtraction of Two Matrices


C Program for subtraction of two matrices 

#include<stdio.h>
#include<conio.h>

//Read Matrix
void read_mat(float a[][10],int m,int n)
{
int i,j;
printf("\n\nEnter %d X %d matrix below:\n",m,n);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%f",&a[i][j]);
}

//Write Matrix
void write_mat(float a[][10],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%10.2f",a[i][j]);
printf("\n");
}
}

//Subtract matrices
void sub_mat(float a[][10],float b[][10],float c[][10],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j]=a[i][j] - b[i][j];
}

//main function
void main()
{
float x[10][10],y[10][10],z[10][10];
int m,n;
clrscr();

//Accept two matrices
printf("\n\nEnter order of matrix \n");
scanf("%d %d",&m,&n);
read_mat(x,m,n);
read_mat(y,m,n);

//call sub_mat() function
sub_mat(x,y,z,m,n);
printf("\n\nSUBTRACTION OF THE GIVEN MATRICES IS:\n");
write_mat(z,m,n);
getch();
}

Labels