fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int arr[3][3]= {{1,2,3},{4,5,6},{7,8,9}};
  7. int row= sizeof(arr)/sizeof(arr[0]);
  8. int col= sizeof(arr[0])/sizeof(arr[0][0]);
  9.  
  10. for(int i=0;i<row;i++){
  11. for(int j=0;j<col;j++){
  12. if(i==j){
  13. cout<<arr[i][j]<<" ";
  14. }
  15. }
  16. }
  17.  
  18. cout<<endl;
  19.  
  20. for(int i=0;i<row;i++){
  21. for(int j=0;j<col;j++){
  22. if(i+j==row-1 && i!=j){
  23. cout<<arr[i][j]<<" ";
  24. }
  25. }
  26. }
  27. }
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
1 5 9 
3 7