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

please give me some tips for the placement in the TCS.

2114


Write a program with dynamically allocation of variable.

1130


What are the types of variables in c?

1020


Is main is user defined function?

1147


What are the two forms of #include directive?

1167


Can we change the value of constant variable in c?

1059


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3685


Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

3248


What is use of pointer?

1088


What are the types of c language?

1033


Explain null pointer.

1116


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

1071


What is the difference between far and near ?

1193


How are pointers declared in c?

1062


Explain what are bus errors, memory faults, and core dumps?

1277