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...

Given an unsigned integer, find if the number is power of 2?

Answer Posted / coder

#include<stdio.h>
void powerOfTwo(int number)
{
if(!(number & number-1) && number)
printf("\nthe number is a power of 2\n");
else printf("\nThe number is not a power of 2\n");
}


int main()
{
powerOfTwo(32); //power of 2
powerOfTwo(22); //not a power of 2
return 0;
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between local variable and global variable in c?

1238


Are global variables static in c?

1172


How do you print only part of a string?

1023


What is the code for 3 questions and answer check in VisualBasic.Net?

2164


Where we use clrscr in c?

1141


What is uint8 in c?

1106


What are reserved words with a programming language?

1142


What is double pointer in c?

1043


What is zero based addressing?

1178


What are identifiers in c?

1204


How can you restore a redirected standard stream?

1124


Is return a keyword in c?

1091


how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions

3179


which is an algorithm for sorting in a growing Lexicographic order

1810


Explain pointer. What are function pointers in C?

1086