Given an unsigned integer, find if the number is power of 2?
Answer Posted / coder
#include<stdio.h>
void powerOfTwo(int number)
{
if(!(number & number-1) && number)
printf("\nthe number is a power of 2\n");
else printf("\nThe number is not a power of 2\n");
}
int main()
{
powerOfTwo(32); //power of 2
powerOfTwo(22); //not a power of 2
return 0;
}
| Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
What is hashing in c?
the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset
Is there any data type in c with variable size?
What is structure in c definition?
What is #include cctype?
How can I remove the trailing spaces from a string?
What is stack in c?
What is dangling pointer in c?
What is exit() function?
Does c have an equivalent to pascals with statement?
write a program to print data of 5 five students with structures?
Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?
What are directives in c?
Is linux written in c?
What is the significance of c program algorithms?