# Answer to Question #24432 in C++ for adrian thomas

Question #24432

7.Enter a 3*3 matrix and display the diagonal element.

Expert's answer

#include <iostream>

#include <conio.h>

using namespace std;

void main(){

int a=0,b=0,i,j,s,c[3][3]; //initialising matrix

cout<<"Enter Values into Matrix of side(s)

";

for(i=0; i<3; i++) {

for(j=0; j<3; j++){

cin>>c[i][j];

}

}

cout<<"

The Given Matrix is

"; // Output MAtrix

for(i=0; i<3; i++) {

cout<<"

";

for(j=0; j<3; j++){

cout<<c[i][j];

}

}

cout<<"

Diagonal element: ";

for(i=0; i<3; i++) {

cout<<"

";

for(j=0; j<3; j++){

if(i==j){

cout<<c[i][j];

}

}

}

cout<<"

";

getch();

}

#include <conio.h>

using namespace std;

void main(){

int a=0,b=0,i,j,s,c[3][3]; //initialising matrix

cout<<"Enter Values into Matrix of side(s)

";

for(i=0; i<3; i++) {

for(j=0; j<3; j++){

cin>>c[i][j];

}

}

cout<<"

The Given Matrix is

"; // Output MAtrix

for(i=0; i<3; i++) {

cout<<"

";

for(j=0; j<3; j++){

cout<<c[i][j];

}

}

cout<<"

Diagonal element: ";

for(i=0; i<3; i++) {

cout<<"

";

for(j=0; j<3; j++){

if(i==j){

cout<<c[i][j];

}

}

}

cout<<"

";

getch();

}

## Comments

## Leave a comment