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 are all different types of pointers in c?
Why does everyone say not to use scanf? What should I use instead?
Do you know null pointer?
diff between exptected result and requirement?
the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above
hi... can anyone help me to make a two-dimensinal arrays in finding the sum of two elements plzzz. thnx a lot...
How does selection sort work in c?
What is header file definition?
Why are algorithms important in c program?
What is ctrl c called?
What is a char c?
a program that can input number of records and can view it again the record
Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014 Npu university
Why is c so popular?
This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory