Computer Scientists are Pretty Pessimistic

Friday 4 September 2015

WAP to find out the sum and difference of two matrices.

#include <stdio.h>
int main ()
{
    int a[3][3],b[3][3],c[3][3],i,j;
    printf("Enter 1st Matrix (3x3):\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    printf("Enter 2nd Matrix (3x3):\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&b[i][j]);
        }
    }
    printf("The sum of two matrix:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            c[i][j]=a[i][j]+b[i][j];
            printf("%d ",c[i][j]);
        }
        printf("\n");
    }
    printf("The difference of two matrix:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            c[i][j]=a[i][j]-b[i][j];
            printf("%d ",c[i][j]);
        }
        printf("\n");
    }
    return 0;
}

No comments:

Post a Comment