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
What is a volatile keyword in c?
What is the benefit of using const for declaring constants?
What type of function is main ()?
Write a program to check whether a number is prime or not using c?
What are the basic data types associated with c?
What is the right type to use for boolean values in c? Is there a standard type?
What is the difference between class and object in c?
how to create duplicate link list using C???
What is the size of a union variable?
Function calling procedures? and their differences? Why should one go for Call by Reference?
my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?
What is meant by preprocessor in c?
What is the use of in c?
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.
What language is windows 1.0 written?