Thursday, 26 January 2012

Program To Print Right Diagonal Matrix In C++

#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a[5][5],i,j,m,n;
cout<<"enter number of rows=";
cin>>m;
cout<<"enter number of coloumnss=";
cin>>n;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"a["<<i<<"]["<<j<<"]=====>>";
cin>>a[i][j];
}
}
cout<<"\n==================matrix is=============\n";

for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t"<<a[i][j];
}
cout<<"\n";

}

cout<<"\n==========right diagonal matrix is============\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i+j==2)
{
 cout<<"\t"<<a[i][j];
 }
 else
 {
 cout<<"\t";
 }
 }
 cout<<"\n";
 }


getch();
}

No comments:

Post a Comment