Advertisement
Egor_1425

Untitled

Jul 12th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void f(int n);
  5.  
  6. void del(int n)
  7. {
  8.     if(n > 0){
  9.  
  10.         del(n-2);
  11.         cout<<-n<<" ";
  12.         f(n-2);
  13.         del(n-1);
  14.        
  15.     }
  16. }
  17. void f(int n)
  18. {
  19.     if(n > 0)
  20.     {
  21.         f(n-1);
  22.         del(n-2);
  23.         cout<<n<<" ";
  24.         f(n-2);
  25.     }
  26. }
  27. int main(){
  28.  
  29.     int n;
  30.     cin>>n;
  31.  
  32.     f(n);
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement