Question { nvidia, 40504 }
Function to find the given number is a power of 2 or not?
Answer
int ispwrof2(int num)
{
int temp = 0;
if(num <= 0)
return 0;
else if(num > 0)
{
while(num%2 == 0)
{
temp = num/2;
num = temp;
}
}
if(num == 1)
return 1;
else
return 0;
}