SubhanXd
Centipat
- Katılım
- 5 Kasım 2022
- Mesajlar
- 186
- Çözümler
- 1
Selamlar. Yapmam gereken şu:
Given a natural number N, determine if it is a power of 2.
Output Format
Print "Yes" if N is a power of 2, otherwise print "No".
Yazdığım kod :
Given a natural number N, determine if it is a power of 2.
Output Format
Print "Yes" if N is a power of 2, otherwise print "No".
Yazdığım kod :
C++:
int main() {
int num ;
cin >> num ;
int f = 0 ;
while (num>=1) {
if(num == 1 ) {
cout << "Yes" << endl;
break ; } else {
f = num %2 ;
num = num / 2 ; }
}
while (num>=1) {
if (f ==0) {
cout << "Yes" << endl ;
break ;
} else {
cout << "No" << endl ;
break ;
}
}
}