Program to check whether given matrix is diagonal matrix or not

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 5

int main()
{
int a[MAX][MAX],i,j;
cout<<"\nEnter the matrix row wise :";

for(i=0;i<MAX;i++)
{
     for(j=0;j<MAX;j++)
     {
        cout<<"\n Enter a["<<i<<"]["<<j<<"]element : ";
        cin>>a[i][j];
       }
}

for(i=0;i<MAX;i++)
{
      for(j=0;j<MAX;j++)
      {
           if(i!=j && a[i][j]!=0)
           {
              cout<<"\nMatrix is not diagonal matrix";
          getch(); exit(0);
           }
      }
}
cout<<"\nMatrix is diagonal matrix";
getch();
return(0);
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|