WAP TO CREATE DIAGONAL OF MATRIX ELEMENTS
#include<iostream.h>
#include<conio.h>
Void main()
{
int a[3][3],i,j;
clrscr();
cout<<”Enter the matrix elements:”;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a[i][j];
}
}
cout<<”Matrix elements are:”;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j];
cout<<”\t”;
}
cout<<”\n”;
}
cout<<”Diagonal elements of matrix
are:”;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
cout<<a[i][j];
else
cout<<” “;
cout<<”\t”;
}
cout<<”\n”;
}
getch();
}
Comments
Post a Comment