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 the advantages of using Unions?
I need previous papers of CSC.......plz help out by posting them.......
Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)
Explain what is output redirection?
Who is the main contributor in designing the c language after dennis ritchie?
When should I declare a function?
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
What are the rules for identifiers in c?
Why is it that not all header files are declared in every C program?
How many types of errors are there in c language? Explain
What are the complete rules for header file searching?
How can I invoke another program (a standalone executable, or an operating system command) from within a c program?
How can a program be made to print the line number where an error occurs?
What is #include cctype?
Add Two Numbers Without Using the Addition Operator