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

How important is structure in life?

1091


When should a far pointer be used?

1140


Differentiate between the = symbol and == symbol?

1302


What is scope and lifetime of a variable in c?

1079


What is spaghetti programming?

1145


Explain how do you determine a file’s attributes?

1050


Which is an example of a structural homology?

1328


In c programming, explain how do you insert quote characters (? And ?) Into the output screen?

1252


When c language was developed?

1066


What is the purpose of the preprocessor directive error?

1276


What is return type in c?

1143


Where are the auto variables stored?

1154


Explain how can you be sure that a program follows the ansi c standard?

1481


Can you please explain the scope of static variables?

1063


Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?

2136