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 the g value paradox?

647


Differentiate abs() function from fabs() function.

602


What is const and volatile in c?

570


Explain what are compound statements?

608


Is stack a keyword in c?

640






What is the use of sizeof () in c?

562


What is the difference between procedural and declarative language?

657


What is strcmp in c?

603


Where are the auto variables stored?

628


What is keyword in c?

606


what value is returned to operating system after program execution?

1608


hi any body pls give me company name interview conduct "c" language only

1671


Do you have any idea how to compare array with pointer in c?

609


develop algorithms to add polynomials (i) in one variable

1747


In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.

1385