Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / udhaya

Find if the given number is a power of 2.
//include math.h
void main()
{
int n,logval,powval;
printf("Enter a number to find whether it is s power of
2\n");
scanf("%d",&n);
logval=log(n)/log(2);
powval=pow(2,logval);
if(powval==n)
printf("The number is a power of 2");
else
printf("The number is not a power of 2");
getch();
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are header files and what are its uses in C programming?

1248


What is union and structure in c?

1234


How many levels of pointers have?

1056


how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

1947


What is function definition in c?

1084


What is a macro in c preprocessor?

1107


What is a far pointer in c?

1049


What is the difference between local variable and global variable in c?

1239


What is structure in c definition?

1059


Explain how do you use a pointer to a function?

1116


write an algorithm to display a square matrix.

2716


How to set file pointer to beginning c?

1205


What is the description for syntax errors?

1175


What is the c value paradox and how is it explained?

1062


What is the size of array float a(10)?

1148