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 / rajiv malhotra

/* THIS SOLUTION IS 100% CORRECT */

#include<stdio.h>
int isPowerOf2(float n)
{
while(n>1)
{
n/=2.0;
}
return (n==1)?1:0; /* 1-> TRUE; 0-> FALSE*/
}
void main()
{
int x,n;
printf("enter a number\n");
fflush(stdin);
scanf("%d",&n);
x=isPowerOf2(n);
if(x==1)
printf("\n yes");
else
printf("\n no");
}

Is This Answer Correct ?    7 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell me what are bitwise shift operators?

1132


Why is structure important for a child?

1103


How can you find the day of the week given the date?

1202


What is the difference between typedef struct and struct?

1110


How can I implement sets or arrays of bits?

1047


What is new line escape sequence?

1349


Do variables need to be initialized?

1051


What is the purpose of 'register' keyword?

1098


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?

1135


number of times a digit is present in a number

2039


What are the different properties of variable number of arguments?

1161


What does emoji p mean?

1116


Write a program to find the biggest number of three numbers in c?

1045


What are linker error?

1095


can anyone suggest some site name..where i can get some good data structure puzzles???

2084