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

Answer Posted / asis bera

main()
{
unsigned int n;
printf("enter the number:\n");
scanf("%u",&n);
if(i&(i-1))
printf(" not power of two\n");
else
printf("power of two...\n");
}

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 significance of scope resolution operator?

865


What is the purpose of sprintf?

625


How can you determine the size of an allocated portion of memory?

748


Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?

985


How do you define a string?

659






Why can't I perform arithmetic on a void* pointer?

639


Do you know the purpose of 'register' keyword?

646


Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?

761


What is difference between structure and union in c?

551


How reliable are floating-point comparisons?

632


What is the explanation for modular programming?

689


What is a file descriptor in c?

568


Write a simple code fragment that will check if a number is positive or negative.

711


What is getche() function?

613


Which is more efficient, a switch statement or an if else chain?

585