Answer to Question #24432 in C++ for adrian thomas
7.Enter a 3*3 matrix and display the diagonal element.
1
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!
Learn more about our help with Assignments:
C++
Comments
Leave a comment