MATRIX
SUBTRACTION
#include<stdio.h>
#include<conio.h>
void main()
{int
a[5][5],b[5][5],c[5][5],I,j,n,m,p,q;
Clrscr();
Printf(“enter the rows and columns of
the first matrix”);
Scanf(“%d%d”,&m,&n);
Printf(“enter the first matrix”);
for(i=0;i<m;i++)
{for(j=0;j<n;j++)
Scanf(“%d”,&a[i][j]);
}
Printf(“enter the rows and columns of
the second matrix”);
Scanf(“%d%d”&p,&q);
Printf(“enter the second matrix”);
for(i=0;i<p;i++)
{for(j=0;j<q;j++)
Scanf(“%d”b[i][j]);
}
Printf(“\nfirst matrix”);
For(i=0,i<m;i++)
{for(j=0;j<n;j++)
Printf(“%d”,a[i][j]);
Printf(“\n”);
}
Printf(\n”);
Printf(“second matrix”);
For(i=0;i<p;i++)
{for(j=0;j<q;j++)
Printf(“%d”,b[i][j]);
Printf(“\n”);
}
If(m==p&&n==q)
{printf(“difference is\n”);
For(i=0;i<m;i++)
{for(j=0;j<n;j++)
{c[i][j]=a[i][j]-b[i][j];
Printf(:%d”,c[i][j]);
}
Printf(“\n”);
}
}
else
Printf(“subtraction is not
possible”);
getch(); }
OUTPUT
Enter the number of rows and columns
of the first matrix
2
3
Enter the lements of the first matrix
5 6 4 1 2 3
Enter the number of rows and columns
of the second matrix
2
3
Enter the elements of the second
matrix
2 3 4 1 1 2
First matrix
8 6 4
9 2 3
Second matrix
2 3 4
3 1 0
Difference is
6 3 0
6 1 3






0 comments:
Post a Comment