Function to find the given number is a power of 2 or not?
Answer Posted / santhi perumal
#include<stdio.h>
#include<conio.h>
int main()
{
int i,count = 0,number;
printf("Enter the number\n");
scanf("%d",&number);
for(i=15;i>=0;i--)
{
if((1<<i) & number)
count++;
}
if(count == 1)
printf("\nThe Given Number is Power of 2\n");
else
printf("\nThe Given Number is Not Power of 2\n");
}
| Is This Answer Correct ? | 7 Yes | 1 No |
Post New Answer View All Answers
How many main () function we can have in a project?
how can use subset in c program and give more example
What are bitwise shift operators in c programming?
What is the purpose of & in scanf?
Explain the properties of union. What is the size of a union variable
What are 3 types of structures?
What does void main () mean?
What are pointers really good for, anyway?
what is different between auto and local static? why should we use local static?
Can a function argument have default value?
Describe newline escape sequence with a sample program?
What is methods in c?
What are the 5 types of inheritance in c ++?
What is the difference between ++a and a++?
What are types of structure?