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 identifier in c?
What is a file descriptor in c?
Can include files be nested?
what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)
Why we not create function inside function.
what are bit fields? What is the use of bit fields in a structure declaration?
write a program for the normal snake games find in most of the mobiles.
What is the use of in c?
Write a program on swapping (100, 50)
What are 'near' and 'far' pointers?
What is character set?
difference between native and cross compilers
Are global variables static in c?
Tell me when is a void pointer used?
write a program to input 10 strings and compare without using strcmp() function. If the character of one string matches with the characters of another string , sort them and make it a single string ??? example:- str1="Aakash" st2="Himanshu" str="Uday" output:- Aakashimanshuday (please post the answer as quickly as possible)