Узнать есть ли число , которое нужно ввести степенью двух Выводит YES, если число есть степенью 2, NO – если не есть степенью 2.
#include <iostream> using namespace std; bool p2(int n) { return ( n & (n - 1) ) == 0; } int main() { int val; cout << "Enter value: "; cin >> val; if(p2(val)) cout << "YES"; else cout << "NO"; return 0; } Код #include <iostream> using namespace std; bool p2(int n) { return ( n & (n - 1) ) == 0; } int main() { int val; cout << "Enter value: "; cin >> val; if(p2(val)) cout << "YES"; else cout << "NO"; return 0; }