Function to find the given number is a power of 2 or not?
Answer Posted / anyone
//Revision for Ahmed Ihmeid answer:
//Operator % prototype: int % int
bool isPowerOf2(int num)
{
int x;
x = num % (int(ceil(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 % 5 != 0
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
Are comments included during the compilation stage and placed in the EXE file as well?
What is the value of uninitialized variable in c?
What are the applications of c language?
which is an algorithm for sorting in a growing Lexicographic order
What is sorting in c plus plus?
Explain bitwise shift operators?
Why is void main used?
Can a function argument have default value?
How #define works?
Can we access the array using a pointer in c language?
What is LINKED LIST? How can you access the last element in a linked list?
What is clrscr ()?
Write a code on reverse string and its complexity.
What is the use of c language in real life?
What are local static variables?