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
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
Give me the code of in-order recursive and non-recursive.
When would you use a pointer to a function?
Explain Basic concepts of C language?
How is a pointer variable declared?
How do you print only part of a string?
What is 2 d array in c?
Explain is it valid to address one element beyond the end of an array?
What is a lookup table in c?
Write a C program to help a HiFi’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the HiFi’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the HiFi’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
What is the full form of getch?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
What is data type long in c?
How many bytes is a struct in c?