Function to find the given number is a power of 2 or not?

Answer Posted / s.v.prasad reddy,lifetree conv

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int num,i=0,flag;
clrscr();
printf("\nEnter the number:=");
scanf("%d",&num);

if(num==0 || num==1 || (num%2)!=0) /* Validation Part */
{
printf("\n We can't express the given number to power
of 2");
return;
}

for(;;}
{
if(pow(2,i)==num)
{
flag=1;
break;
}
if(pow(2,i)>num)
{
flag=0;
break;
}
i++;
}
if(falg==1)
printf("\n %d number is 2 power of %d",num,i);
else
printf("\n%d number can't be expressed as power of 2",num);

getch();
}

Is This Answer Correct ?    3 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain which function in c can be used to append a string to another string?

594


What does static variable mean in c?

657


What is gets() function?

675


How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?

598


What is the difference between struct and union in C?

580






Do you know the use of 'auto' keyword?

665


What are lookup tables in c?

552


What is the use of getchar functions?

681


How can you restore a redirected standard stream?

615


Why doesnt the call scanf work?

679


Tell me when is a void pointer used?

651


What is the method to save data in stack data structure type?

612


Explain two-dimensional array.

633


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

2561


write a program fibonacci series and palindrome program in c

633