Advertisement
desislava_shunina

Task_5

Oct 23rd, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | Source Code | 0 0
  1. #include <iostream>
  2. int main() {
  3.     unsigned int n;
  4.     std::cin >> n;
  5.     bool isPowerOfTwo = false;
  6.     for (int i = 1;i>0 ; i++) {
  7.         if (n == 1) {
  8.             isPowerOfTwo = true;
  9.             break;
  10.         }
  11.         else {
  12.             if (n % 2 == 0) {
  13.                 n = n / 2;
  14.             }
  15.             else {
  16.                 isPowerOfTwo = false;
  17.                 break;
  18.             }
  19.         }
  20.     }
  21.     std::cout << isPowerOfTwo;
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement