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

What is nested structure?

576


Differentiate abs() function from fabs() function.

598


Why functions are used in c?

587


how can use subset in c program and give more example

1502


how to construct a simulator keeping the logical boolean gates in c

1730






find out largest elemant of diagonalmatrix

1651


Why is c platform dependent?

624


How can I find the modification date and time of a file?

604


Is null a keyword in c?

737


What are reserved words with a programming language?

604


How can I read and write comma-delimited text?

622


FILE PROGRAMMING

1780


Why is c so powerful?

687


Explain null pointer.

623


When should volatile modifier be used?

557