Given an unsigned integer, find if the number is power of 2?
Answer Posted / coder
#include<stdio.h>
void powerOfTwo(int number)
{
if(!(number & number-1) && number)
printf("\nthe number is a power of 2\n");
else printf("\nThe number is not a power of 2\n");
}
int main()
{
powerOfTwo(32); //power of 2
powerOfTwo(22); //not a power of 2
return 0;
}
Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
Is main is a keyword in c?
Write a program to swap two numbers without using the third variable?
What is the symbol indicated the c-preprocessor?
any restrictions have on the number of 'return' statements that may be present in a function. a) no restriction b) only 2 return statements c) only 1 return statements d) none of the above
What is difference between structure and union?
How can I remove the trailing spaces from a string?
Are pointers integer?
What is the difference between %d and %i?
Explain data types & how many data types supported by c?
how to make a scientific calculater ?
Explain what is the difference between far and near ?
Apart from dennis ritchie who the other person who contributed in design of c language.
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
What are the advantages of using macro in c language?
What is string length in c?