Advertisement
chevengur

СПРИНТ № 5 | Итераторы | Урок 7: Стандартные алгоритмы — рекурсия 2/3

Jan 15th, 2024
1,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <set>
  4. #include <string>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int IsPowOfTwo(int x){
  10.     if(x == 1)
  11.         return true;
  12.    
  13.     if(x == 0)
  14.         return false;
  15.  
  16.     if(x % 2 == 0)
  17.         return IsPowOfTwo(x/2);
  18.  
  19.     return false;
  20. }
  21.  
  22. int main() {
  23.     int result = IsPowOfTwo(10);
  24.     cout << result << endl;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement