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 / anyone

//Revision for Ahmed Ihmeid answer:
//Operator % prototype: int % int

bool isPowerOf2(int num)
{
int x;

x = num % (int(ceil(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 % 5 != 0

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Are comments included during the compilation stage and placed in the EXE file as well?

1031


What is the value of uninitialized variable in c?

980


What are the applications of c language?

1014


which is an algorithm for sorting in a growing Lexicographic order

1749


What is sorting in c plus plus?

928


Explain bitwise shift operators?

1174


Why is void main used?

1036


Can a function argument have default value?

1094


How #define works?

1051


Can we access the array using a pointer in c language?

1000


What is LINKED LIST? How can you access the last element in a linked list?

1021


What is clrscr ()?

1059


Write a code on reverse string and its complexity.

983


What is the use of c language in real life?

975


What are local static variables?

1084