Function to find the given number is a power of 2 or not?
Answer Posted / udhaya
Find if the given number is a power of 2.
//include math.h
void main()
{
int n,logval,powval;
printf("Enter a number to find whether it is s power of
2\n");
scanf("%d",&n);
logval=log(n)/log(2);
powval=pow(2,logval);
if(powval==n)
printf("The number is a power of 2");
else
printf("The number is not a power of 2");
getch();
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What are header files and what are its uses in C programming?
What is union and structure in c?
How many levels of pointers have?
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?
What is function definition in c?
What is a macro in c preprocessor?
What is a far pointer in c?
What is the difference between local variable and global variable in c?
What is structure in c definition?
Explain how do you use a pointer to a function?
write an algorithm to display a square matrix.
How to set file pointer to beginning c?
What is the description for syntax errors?
What is the c value paradox and how is it explained?
What is the size of array float a(10)?