0
Please, how to print the diagonal elements of array with if else conditions?
2 Antworten
+ 1
for(r=0; r<2; r++){
for(c=0; c<2; c++){
if(r!=c){
cout << " ";
}
else if(r==c){
cout << a[r][c] << " ";
cout << endl;}
}}
0
You don't need conditions for this
#include <iostream>
using namespace std;
int main() {
int a[2][2]={{1,3},{4,2}};
for(int r=0; r<2; r++)
cout << a[r][r] << " ";
return 0;
}