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


Please Help Members By Posting Answers For Below Questions

Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?

595


Give me the code of in-order recursive and non-recursive.

878


When would you use a pointer to a function?

581


Explain Basic concepts of C language?

637


How is a pointer variable declared?

588






How do you print only part of a string?

606


What is 2 d array in c?

544


Explain is it valid to address one element beyond the end of an array?

727


What is a lookup table in c?

618


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

2549


find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2

1522


What is the full form of getch?

576


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?

596


What is data type long in c?

621


How many bytes is a struct in c?

719