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
Is using exit() the same as using return?
Explain how do you print only part of a string?
What does struct node * mean?
What is variable and explain rules to declare variable in c?
What is the advantage of an array over individual variables?
What is pointer to pointer in c with example?
Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.
Explain 'far' and 'near' pointers in c.
What is array of pointers to string?
What are type modifiers in c?
What is variables in c?
What is a program flowchart and how does it help in writing a program?
How can I ensure that integer arithmetic doesnt overflow?
How to create struct variables?
What are static variables in c?