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 / ahmed ihmeid

bool isPowerOf2(int num)
{
float x;

x = num % (sqrt(num));

if( x == 0)
return true; //it is a power of 2
else
return false; //it is not
}

proof:
4 % 2 = 0
16 % 4 = 0
22 % 4.7 != 0

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the 4 data types?

963


what is bit rate & baud rate? plz give wave forms

1914


why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???

1912


What does node * mean?

1142


What is mean by Data Driven framework in QTP? Can any one answer me in details on this regard.

2203


What is the size of enum in bytes?

1035


Disadvantages of C language.

1045


What is the purpose of & in scanf?

1008


Why do we use return in c?

950


How can I access an I o board directly?

1036


#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }

1109


Is anything faster than c?

968


Can we assign string to char pointer?

1041


What is the argument of a function in c?

990


What is the difference between array_name and &array_name?

1239