Function to find the given number is a power of 2 or not?
Answer Posted / ahmed ihmeid
bool isPowerOf2(int num)
{
float x;
x = num % (sqrt(num));
if( x == 0)
return true; //it is a power of 2
else
return false; //it is not
}
proof:
4 % 2 = 0
16 % 4 = 0
22 % 4.7 != 0
Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
What is int main () in c?
What is function and its example?
What is the heap in c?
How can I find out if there are characters available for reading?
What are types of functions?
How can I split up a string into whitespace-separated fields?
What is external variable in c?
Explain what are multidimensional arrays?
what are # pragma staments?
Explain function?
5 Write an Algorithm to find the maximum and minimum items in a set of ānā element.
What is a sequential access file?
What are c preprocessors?
When c language was developed?
What are structure members?