adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C to check a given matrix is diagonal or not.

Program in C to check a given matrix is diagonal or not.


#include<stdio.h>
#include<conio.h>
   int main()
    {
     int m[3][3],i,j,s,d=0,u=0,l=0;
  printf("Enter a matrix of size 3 * 3::-\n");
  for(i=0;i<3;i++)
    {
     for(j=0;j<3;j++)
      scanf("%d",&m[i][j]);
      }
        for(i=0;i<3;i++)
            {
     for(j=0;j<3;j++)
             if(i==j)
              {
       if(m[i][j]>0)
                 d++;
     }
     else
      {
       if(m[i][j]==0)
         u++;
      }
  }
     if(d==3&&u==6)
        printf("Given matrix is  a diagonal matrix.");
       else
        printf("Given matrix is not a diagonal matrix.");

     getch();
     }
Output:-




Post a Comment

0 Comments