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