write a C Program for subtraction of two matrices
/* C Program for subtraction of two matrices*/
/*author:sai date:7-4-2015 */
#include<stdio.h>
int main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n,p,q;
printf("enter order first matrix\n");
scanf("%d%d",&m,&n);
printf("enter elements of first matrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("enter order of second matrix");
scanf("%d%d",&p,&q);
printf("\n enter elements of second matrix\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<q;j++)
{
c[i][j]=0;
c[i][j]=a[i][j]-b[i][j];
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("\t%d",c[i][j]);
printf("\n");
}
}
output:
/* C Program for subtraction of two matrices*/
/*author:sai date:7-4-2015 */
#include<stdio.h>
int main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n,p,q;
printf("enter order first matrix\n");
scanf("%d%d",&m,&n);
printf("enter elements of first matrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("enter order of second matrix");
scanf("%d%d",&p,&q);
printf("\n enter elements of second matrix\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<q;j++)
{
c[i][j]=0;
c[i][j]=a[i][j]-b[i][j];
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("\t%d",c[i][j]);
printf("\n");
}
}
output:
No comments:
Post a Comment