fork(1) download
  1. // Online C++ compiler to run C++ program online
  2. #include <iostream>
  3. using namespace std;
  4. int main() {
  5. int n ;
  6. cout << "Enter the number: ";
  7. cin >> n ;
  8. for (int i = 0 ; i < n ; i++){
  9. for (int x = 1 ; x <= i ; x++) cout << n - i + x << " " ;
  10. for (int j = 1 ; j <= n - i ; j++) cout << j << " " ;
  11. cout << '\n' ;
  12. }
  13. return 0;
  14. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
stdout
Enter the number: 1 2 3 4 5 
5 1 2 3 4 
4 5 1 2 3 
3 4 5 1 2 
2 3 4 5 1