Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int ciag(int n)
  5. {
  6.     if(n==2)
  7.     {
  8.         cout << "2 ";
  9.         return 2;
  10.     }
  11.  
  12.     if(n%2==1)
  13.         {int x = ciag(n-1)*2;
  14.             cout<<x<<" ";
  15.          return x;
  16.         }
  17.     else
  18.         {int x = ciag(n-1)+2;
  19.         cout<<x<<" ";
  20.          return x;
  21.         }
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27.     int n;
  28.     cin >> n;
  29.  
  30.     cout << ciag(n) << endl;
  31.  
  32.  
  33.  
  34.  
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement