Computer Scientists are Pretty Pessimistic

Friday 4 September 2015

Write a function to check the equality of two matrices. Matrices are passed to the function as argument and function returns 1 if they are equal else returns 0.

#include <stdio.h>
int check (int a[3][3],int b[3][3]);
int main ()
{
    int i,j,a[3][3],b[3][3],res;
    printf("Enter 1st matrix:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    printf("Enter 2nd matrix:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&b[i][j]);
        }
    }
    res=check(a,b);
    printf("\n%d\n",res);
    return 0;
}

int check (int a[3][3],int b[3][3])
{
    int i,j,c=0;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            if(a[i][j]==b[i][j])
                c++;
        }
    }
    if(c==9)
        return 1;
    else
        return 0;
}

No comments:

Post a Comment