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 / swathi sharma

#include<stdio.h>
int main()
{
int num,i=1;
printf("Enter the number:");
scanf("%d", &num);
do
{
i=i*2;
if(i==num)
{
printf("\n The no.is power of 2.");
break;
}
else if(i>num)
{
printf("\n The no. is not power of 2");
break;
}
}
while(i != num);
return 0;
}

Is This Answer Correct ?    8 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If fflush wont work, what can I use to flush input?

1116


Who invented b language?

1430


What is c language and why we use it?

1086


What are loops in c?

1021


Write a code of a general series where the next element is the sum of last k terms.

1051


The file stdio.h, what does it contain?

1175


What is linear search?

1146


What is #define?

1130


Is it fine to write void main () or main () in c?

1042


Is main is a keyword in c?

1139


What is the purpose of scanf() and printf() functions?

1255


Is main a keyword in c?

1146


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

999


What is character constants?

1197


what will be maximum number of comparisons when number of elements are given?

1916