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

In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

1232


Tell me what is null pointer in c?

1086


Explain what are preprocessor directives?

1073


What is "Duff's Device"?

1175


How can I manipulate strings of multibyte characters?

1115


What is a program flowchart and how does it help in writing a program?

1148


What is a wrapper function in c?

1125


Explain how does flowchart help in writing a program?

1126


what do you mean by inline function in C?

1062


When do we get logical errors?

1132


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

1130


What is a protocol in c?

1015


By using C language input a date into it and if it is right?

1087


What are pointers? What are different types of pointers?

1152


What is #define?

1123