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
What is the difference between text and binary i/o?
State the difference between realloc and free.
What does c value mean?
while initialization of array why we use a[][2] why not a[2][]...?
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?
write a program to generate address labels using structures?
How old is c programming language?
Is null equal to 0 in sql?
Is using exit() the same as using return?
What is data structure in c and its types?
Why pointers are used?
What are preprocessor directives in c?
Do pointers store the address of value or the actual value of a variable?
If I have a char * variable pointing to the name of a function ..
What is the difference between #include