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 the difference between array and linked list in c?
Is it valid to address one element beyond the end of an array?
write a program to find the given number is prime or not
How can you call a function, given its name as a string?
Can two or more operators such as and be combined in a single line of program code?
the question is that what you have been doing all these periods (one year gap)
Are bit fields portable?
Are negative numbers true in c?
What does it mean when a pointer is used in an if statement?
What are structural members?
how do you programme Carrier Sense Multiple Access
Explain what are multibyte characters?
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10
What is static and volatile in c?
What is difference between %d and %i in c?