Function to find the given number is a power of 2 or not?

Answer Posted / sahil

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;
}

Is This Answer Correct ?    18 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

hi, which software companys will take,if d candidate's % is jst 55%?

1656


Is file a keyword in c?

496


How does pointer work in c?

612


What is the sizeof () a pointer?

543


What is pointer & why it is used?

598






Can stdout be forced to print somewhere other than the screen?

612


Explain how do you search data in a data file using random access method?

691


The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?

762


What is strcmp in c?

592


What is variable declaration and definition in c?

495


In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping

974


What is the auto keyword good for?

616


Why does the call char scanf work?

611


What is a stream?

641


write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1

3275