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 is the purpose of type declarations?
Write a program to show the change in position of a cursor using c
Do variables need to be initialized?
if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.
write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.
What do you mean by invalid pointer arithmetic?
What language is lisp written in?
How many header files are in c?
Why is c platform dependent?
What are global variables?
What are the types of type qualifiers in c?
Explain heap and queue.
Explain what is operator promotion?
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
What is this infamous null pointer, anyway?