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 null pointer constant?

570


Here is a good puzzle: how do you write a program which produces its own source code as output?

573


write a program to display all prime numbers

1426


Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

540


In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]

1929






Do you know what are the properties of union in c?

555


What is the use of #define preprocessor in c?

594


What is calloc()?

602


What are the preprocessor categories?

609


How many types of operators are there in c?

589


What is the process to generate random numbers in c programming language?

584


Why is void main used?

594


Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?

553


What are derived data types in c?

592


When should the volatile modifier be used?

652