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
Explain what is the most efficient way to store flag values?
Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;
What are linked lists in c?
What is graph in c?
Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.
What is structure pointer in c?
Can you please explain the difference between malloc() and calloc() function?
What is the condition that is applied with ?: Operator?
What are the string functions? List some string functions available in c.
What are the advantages of c preprocessor?
Does c have class?
Why cant I open a file by its explicit path?
C program to find all possible outcomes of a dice?
Is c programming hard?
What are the standard predefined macros?