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 / rajiv malhotra

/* THIS SOLUTION IS 100% CORRECT */

#include<stdio.h>
int isPowerOf2(float n)
{
while(n>1)
{
n/=2.0;
}
return (n==1)?1:0; /* 1-> TRUE; 0-> FALSE*/
}
void main()
{
int x,n;
printf("enter a number\n");
fflush(stdin);
scanf("%d",&n);
x=isPowerOf2(n);
if(x==1)
printf("\n yes");
else
printf("\n no");
}

Is This Answer Correct ?    7 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between array and pointer in c?

1089


How are strings stored in c?

972


What is a good data structure to use for storing lines of text?

1033


What is output redirection?

1164


i got 75% in all semester am i eligible for your company

2171


Explain what are header files and explain what are its uses in c programming?

1109


What is the difference between struct and typedef struct in c?

1082


the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above

1197


What are the keywords in c?

1077


which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above

1650


Why do we use int main instead of void main in c?

1100


Can a pointer be volatile in c?

930


In a switch statement, what will happen if a break statement is omitted?

1005


hai iam working in sap sd module for one year and working in lumax ind ltd in desp department but my problem is i have done m.b.a in hr/marketing and working sap sd there is any combination it. can you give right solution of my problem. and what can i do?

2064


Write a program to print factorial of given number without using recursion?

950