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 local variable and global variable in c?
Are global variables static in c?
How do you print only part of a string?
What is the code for 3 questions and answer check in VisualBasic.Net?
Where we use clrscr in c?
What is uint8 in c?
What are reserved words with a programming language?
What is double pointer in c?
What is zero based addressing?
What are identifiers in c?
How can you restore a redirected standard stream?
Is return a keyword in c?
how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions
which is an algorithm for sorting in a growing Lexicographic order
Explain pointer. What are function pointers in C?