fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. int flag_even = 1;
  8. int flag_odd = 1;
  9. for(int i = 0; i < n; i++){
  10. if(i%2 == 0){
  11. for(int j = 0; j < n; ++j){
  12. cout << flag_even << " ";
  13. ++flag_even;
  14. }
  15. cout << endl;
  16. flag_odd = flag_even + n - 1;
  17. }
  18. else{
  19. for(int j = 0; j < n; ++j){
  20. cout << flag_odd << " ";
  21. --flag_odd;
  22. }
  23. cout << endl;
  24. flag_even += n;
  25. }
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5472KB
stdin
3
stdout
1 2 3 
6 5 4 
7 8 9