Function to find the given number is a power of 2 or not?
Answer Posted / swathi sharma
#include<stdio.h>
int main()
{
int num,i=1;
printf("Enter the number:");
scanf("%d", &num);
do
{
i=i*2;
if(i==num)
{
printf("\n The no.is power of 2.");
break;
}
else if(i>num)
{
printf("\n The no. is not power of 2");
break;
}
}
while(i != num);
return 0;
}
| Is This Answer Correct ? | 8 Yes | 3 No |
Post New Answer View All Answers
What is s in c?
Explain how can I prevent another program from modifying part of a file that I am modifying?
i have to apply for the rbi for the post of officers. i need to know abt the entrance questions whether it may be aps or techinical....
Is it better to bitshift a value than to multiply by 2?
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.
exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above
Is malloc memset faster than calloc?
Write a program to print “hello world” without using semicolon?
the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?
What is the difference between break and continue?
What is the difference between new and malloc functions?
program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)
Differentiate between #include<...> and #include '...'
What are variables c?
When should a type cast be used?