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

Question #24432
7.Enter a 3*3 matrix and display the diagonal element.
1
Expert's answer
2013-02-18T09:02:39-0500
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS