Given an unsigned integer, find if the number is power of 2?

Answer Posted / sagar shah

#include<stdio.h>
main()
{
int i,n,r=2
clrscr();
scanf("%d",&n);
for(i=1;i<=n;i=r*i)
{
if(i==n)
{
r=0;
break;
}
}
if (r==0)
{
printf("power of two:");
}
else
{
printf("not power of two:");
}
getch();
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a volatile keyword in c?

636


What is the benefit of using const for declaring constants?

581


What type of function is main ()?

583


Write a program to check whether a number is prime or not using c?

572


What are the basic data types associated with c?

811






What is the right type to use for boolean values in c? Is there a standard type?

560


What is the difference between class and object in c?

581


how to create duplicate link list using C???

2071


What is the size of a union variable?

598


Function calling procedures? and their differences? Why should one go for Call by Reference?

629


my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?

1115


What is meant by preprocessor in c?

531


What is the use of in c?

576


Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.

3689


What language is windows 1.0 written?

573