answered By bhjahnavi 0

```
/*program for printing the elements in the diagonal of a matrix*/
# include <iostream.h>
# include <conio.h>
void main()
{
int i, j, r = 0, c = 0;
int a [ 10 ][ 10 ];
clrscr();
cout << " Enter Number Of Rows & Columns Of 2D Array [ Matrix ] : ";
cin >> r >> c ;
cout << " Enter " << r * c << " Values for 2D Array : ";
for ( i = 0; i < r; i++ )
{
for ( j = 0; j < c; j++ )
{
cin >> a [ i ][ j ];
}
}
cout << " Values Of 2D Array [ Matrix ] Are : ";
for ( i = 0; i < r; i++ )
{
cout << " \n ";
for ( j = 0; j < c; j++ )
{
cin >> a [ i ][ j ];
}
}
if(r==c)
{
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
if(i+j==0 || i+j==2 || i+j==4)
{
cout<<a[i][j];
}
}
}
}
}
```

flag

Write A Tutorials

Question tags

Similar questions

Follow this question

Follow c++ category

Question tags

c++
× 1

Asked
**2 years and 3 months ago ago**

Number of Views -188

Number of Answers -1

Last updated

**2 years and 2 months ago ago**

Number of Views -188

Number of Answers -1

Last updated

Similar questions