Here is a C++ program to check matrix is diagonal or not
SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
int a[10][10],row,col;
cout<<"Enter row and column of matrix (max 10*10): ";
cin>>row>>col;
cout<<"Enter matrix a1 : "<<endl;
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
cin>>a[i][j];
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
if(i!=j)
{
if(a[i][j]!=0)
{
cout<<"Matrix is not diagonal";
return 0;
}
}
cout<<"Matrix is diagonal ";
return 0;
}
using namespace std;
int main()
{
int a[10][10],row,col;
cout<<"Enter row and column of matrix (max 10*10): ";
cin>>row>>col;
cout<<"Enter matrix a1 : "<<endl;
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
cin>>a[i][j];
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
if(i!=j)
{
if(a[i][j]!=0)
{
cout<<"Matrix is not diagonal";
return 0;
}
}
cout<<"Matrix is diagonal ";
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment