#include <stdio.h>
#include <stdint.h>
// Complete the function
const char* is_power_of_two(uint32_t n) {
// Your logic here
uint8_t cou=0;
for(int i =0; i<=31; i++){
if(n&(0x01<<i)){
cou++;
}
if (cou==2){
return "NO";
}
}
if(cou==0){
return "NO";
}
return "YES";
}
int main() {
uint32_t n;
scanf("%u", &n);
const char* result = is_power_of_two(n);
printf("%s", result);
return 0;
}
Solving Approach
Approach 1: just iterate through the integrer and if count value goes to 2 then return FALSE, however if the vale is 0 the cou value is 0 and 0 is not the power of 0 so just check explicitly for it in the end of the loop and then leave it.