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
Explain why C language is procedural?
How can I recover the file name given an open stream or file descriptor?
How can I list all of the predefined identifiers?
In C programming, how do you insert quote characters (‘ and “) into the output screen?
What is variable initialization and why is it important?
What are structures and unions? State differencves between them.
Which is better pointer or array?
How do you convert strings to numbers in C?
What is the difference between typedef struct and struct?
How many keywords are there in c?
What are formal parameters?
How does free() know explain how much memory to release?
When can a far pointer be used?
hi send me sample aptitude papers of cts?
What is a keyword?