//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<conio>
#include<iostream>
void accept(void);
void display(void);
void diagonal(void);
class matrix
{
int i,j,a[10][10],r1,c1; // r1=rows , c1=columns
public:
void accept(void);
void display(void);
void diagonal(void);
};
void matrix::accept(void)
{
cout<<"\nEnter how many rows : ";
cin>>r1;
cout<<"\nEnter how many columns : ";
cin>>c1;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<"\nEnter element : ";
cin>>a[i][j];
cout<<endl;
}
}
}
void matrix::display(void)
{
cout<<"Matrix is : "<<endl;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<endl;
}
}
void matrix::diagonal(void)
{
cout<<"\nDiagonal of given matrix : "<<endl;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
if(i==j)
cout<<a[i][j]<<"\t";
else
cout<<"\t";
}
cout<<endl;
}
}
void main()
{
matrix s; // object created
s.accept();
s.display();
s.diagonal();
getch();
}
0 Comments