Sunday, May 1, 2016

Check Matrix Identity

Write a Code that Check Matrix identity.



#include <stdio.h>

int main()
{
   int a[10][10];
   int i, j, r, c, flag =1;

   printf("Enter the order of the matrix A\n");
   scanf("%d %d", &r, &c);

   printf("Enter the elements of matrix A\n");
   for(i=0; i<r; i++)
   {
     for(j=0; j<c; j++)
     {
 scanf("%d",&a[i][j]);
     }
   }
   printf("MATRIX A is\n");
   for(i=0; i<r; i++)
   {
     for(j=0; j<c; j++)
     {
 printf("%d\t",a[i][j]);
     }
     printf("\n");
   }

    for(i=0; i<r; i++)
    {
     for(j=0; j<c; j++)
     {
  if(a[i][j] != 1 && a[j][i] !=0)
  {
    flag = 0;
    break;
  }
 }
   }

   if(flag == 1 )
 printf("It is identity matrix\n");
   else
 printf("It is not a identity matrix\n");
}



Share this

0 Comment to "Check Matrix Identity"

Post a Comment