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 / sagar bhagat

#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,flag=0,temp;
clrscr();

printf("\nEnter the number=");
scanf("%d",&num);

if(num<=0)
printf("Plz enter anoter num");
else
{
temp=num;
for(i=1;(i<num) ;i++)
{
if((i*i)==temp)
{
flag=1;
break;
}
}
}
if(flag==1)
printf("\nNumber %d is in power of 2 of %d",num,i);
else
printf("\nNumber %d is not in power of 2 ",num);

getch();
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are different types of operators?

1043


Can an array be an Ivalue?

1092


What is the difference between array and pointer?

1018


why do some people write if(0 == x) instead of if(x == 0)?

1075


What is signed and unsigned?

1062


What is c method?

997


Explain what is the best way to comment out a section of code that contains comments?

1139


Can a file other than a .h file be included with #include?

1165


What are types of structure?

1119


What are the uses of a pointer?

1151


What is break in c?

1029


Why array is used in c?

1016


What are logical errors and how does it differ from syntax errors?

1300


Is it better to bitshift a value than to multiply by 2?

1092


What is selection sort in c?

1094