0

Please, how to print the diagonal elements of array with if else conditions?

https://code.sololearn.com/ch3kCowKCeY1/?ref=app

21st Feb 2021, 8:49 AM
TeaserCode
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;} }}
21st Feb 2021, 9:10 AM
JaScript
JaScript - avatar
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; }
21st Feb 2021, 9:04 AM
Benjamin Jürgens
Benjamin Jürgens - avatar