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
write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.
What is pragma in c?
How can you determine the size of an allocated portion of memory?
How are Structure passing and returning implemented by the complier?
How many bytes is a struct in c?
How will you find a duplicate number in a array without negating the nos ?
What is the easiest sorting method to use?
Write a simple code fragment that will check if a number is positive or negative.
i have a written test for microland please give me test pattern
What are formal parameters?
What does & mean in scanf?
Explain how can I read and write comma-delimited text?
Write a program to generate random numbers in c?
When is a void pointer used?
Where define directive used?