Header Ads

Subtract two Matrices in C

Subtract matrices

C code to subtract matrices of any order. This program finds the difference between corresponding elements of two matrices and then print the resultant matrix.


C programming code:



#include<stdio.h>
int main()
{
    int a[3][3],b[3][3],c[3][3],i,j;

    printf("Enter the number of rows and columns of matrix\n");
   scanf("%d%d", &i, &j);

    printf("Enter the value of first matrix;\n");

    for(i=0;i<=2;i++)
    {
        for(j=0;j<=2;j++)
        {
          scanf("%d",&a[i][j]);
        }
    }
     printf("Enter the value of Second matrix;\n");

    for(i=0;i<=2;i++)
    {
        for(j=0;j<=2;j++)
        {
          scanf("%d",&b[i][j]);
        }
    }
     printf("Subtract of two matrix \n");
    for(i=0;i<=2;i++)
    {
        for(j=0;j<=2;j++)
        {
          c[i][j]=a[i][j]-b[i][j];
          printf("%d ",c[i][j]);
    }
    printf("\n");}
    return 0;}


Output of  Subtract matrix  C program :



No comments

Powered by Blogger.