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
If fflush wont work, what can I use to flush input?
Who invented b language?
What is c language and why we use it?
What are loops in c?
Write a code of a general series where the next element is the sum of last k terms.
The file stdio.h, what does it contain?
What is linear search?
What is #define?
Is it fine to write void main () or main () in c?
Is main is a keyword in c?
What is the purpose of scanf() and printf() functions?
Is main a keyword in c?
Write a program to print factorial of given number without using recursion?
What is character constants?
what will be maximum number of comparisons when number of elements are given?