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 keyword with example?

1128


what value is returned to operating system after program execution?

2184


Explain the use of keyword 'register' with respect to variables.

1105


What is the difference between scanf and fscanf?

1350


What are the disadvantages of c language?

1261


When do we get logical errors?

1175


What is a keyword?

1226


All technical questions

2059


Can you define which header file to include at compile time?

1078


Define and explain about ! Operator?

1049


What is the explanation for prototype function in c?

1036


Write a program on swapping (100, 50)

1169


What is a const pointer in c?

1185


What is actual argument?

1103


What functions are used in dynamic memory allocation in c?

1126