C Program Code for Subtraction of Matrices

Question Types:

Print subtraction of matrices using c programming language ? 
How to find subtraction of matrices using C programming language ?

Program Code:

#include<stdio.h>
int main()
{
int a[2][2] , b[2][2] , c[2][2];
int i, j , k ,l;
// Matrix a ==> Getting elements from user
    printf("Enter elements for matrix A :\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++){
scanf("\t%d",&a[i][j]);
}
}

// Matrix b ==> Getting elements from user
    printf("\nEnter elements for matrix B :\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++){
scanf("\t%d",&b[i][j]);
}
}
// Matrix a ==> displaying code
    printf("\n\nMatrix A: \n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++){
printf("\t %d\t",a[i][j]);
}
printf("\n");
}

// Matrix b ==> displaying code
    printf("\n\nMatrix B: \n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++){
printf("\t %d\t",b[i][j]);
}
printf("\n");
}
// Matix c = Matrix a - Matrix b
   for(i=0;i<2;i++)
   {
    for(j=0;j<2;j++)
    {
    c[i][j] = a[i][j] - b[i][j];
    }
   }
   
// Matrix C ==> Displaying code
    printf("\n\nMatrix C = Matirx A - Matrix B :\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++){
printf("\t %d\t",c[i][j]);
}
printf("\n");
}
return 0;
}

Output:

output .exe file

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.