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 array and linked list in c?

1099


Is it valid to address one element beyond the end of an array?

1136


write a program to find the given number is prime or not

4675


How can you call a function, given its name as a string?

1113


Can two or more operators such as and be combined in a single line of program code?

1323


the question is that what you have been doing all these periods (one year gap)

2032


Are bit fields portable?

1116


Are negative numbers true in c?

1008


What does it mean when a pointer is used in an if statement?

1072


What are structural members?

964


how do you programme Carrier Sense Multiple Access

1935


Explain what are multibyte characters?

1121


Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

15741


What is static and volatile in c?

1186


What is difference between %d and %i in c?

1188