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
What is difference between main and void main?
in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above
Explain how can I convert a string to a number?
stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.
Why do we use main function?
Explain what is the heap?
What is a pointer in c?
What is struct node in c?
What are header files and explain what are its uses in c programming?
What is the role of && operator in a program code?
while initialization of array why we use a[][2] why not a[2][]...?
Tell us something about keyword 'auto'.
Explain what is meant by high-order and low-order bytes?
What is a node in c?
Array is an lvalue or not?