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
Why doesnt this code work?
using for loop sum 2 number of any 4 digit number in c language
Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)
Explain modulus operator.
Explain that why C is procedural?
Explain how can I manipulate strings of multibyte characters?
a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion
What is the difference between array and pointer in c?
Who is the main contributor in designing the c language after dennis ritchie?
What is difference between %d and %i in c?
What is the difference between far and near in c?
What are the types of data structures in c?
Where are c variables stored in memory?
Can variables be declared anywhere in c?
What is the difference between if else and switchstatement