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
please give me some tips for the placement in the TCS.
Write a program with dynamically allocation of variable.
What are the types of variables in c?
Is main is user defined function?
What are the two forms of #include directive?
Can we change the value of constant variable in c?
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.
What is use of pointer?
What are the types of c language?
Explain null pointer.
What is LINKED LIST? How can you access the last element in a linked list?
What is the difference between far and near ?
How are pointers declared in c?
Explain what are bus errors, memory faults, and core dumps?