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
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?
Tell me what is null pointer in c?
Explain what are preprocessor directives?
What is "Duff's Device"?
How can I manipulate strings of multibyte characters?
What is a program flowchart and how does it help in writing a program?
What is a wrapper function in c?
Explain how does flowchart help in writing a program?
what do you mean by inline function in C?
When do we get logical errors?
Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?
What is a protocol in c?
By using C language input a date into it and if it is right?
What are pointers? What are different types of pointers?
What is #define?