Thursday 23 January 2014

Filled Under:

/* WAP to Matrix subtraction */

/* Matrix subtraction */

#include<stdio.h>
#include<conio.h>
void main()
{
    int mat1[3][3],mat2[3][3],sub[3][3],i,j;

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

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

    for(i=0;i<=2;i++)
    {
        for(j=0;j<=2;j++)
        {
            sub[i][j]=mat1[i][j]-mat2[i][j];
        }
    }

    printf("The Sum Of Matrices Is:\n");
    for(i=0;i<=2;i++)
    {
        for(j=0;j<=2;j++)
        {
            printf("\t%d",sub[i][j]);
        }
        printf("\n");
    }
}

0 comments:

Post a Comment