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 null pointer constant?
Here is a good puzzle: how do you write a program which produces its own source code as output?
write a program to display all prime numbers
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
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]
Do you know what are the properties of union in c?
What is the use of #define preprocessor in c?
What is calloc()?
What are the preprocessor categories?
How many types of operators are there in c?
What is the process to generate random numbers in c programming language?
Why is void main used?
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?
What are derived data types in c?
When should the volatile modifier be used?