Function to find the given number is a power of 2 or not?
Answer Posted / hassan noureddine
int isPowrOf2 (unsigned int number)
{
float x;
if (number <= 0) return (0);
x = log(number) / log(2);
return ( (int) ( ((int)x*log(2))/log(number)));
}
| Is This Answer Correct ? | 4 Yes | 6 No |
Post New Answer View All Answers
Here is a good puzzle: how do you write a program which produces its own source code as output?
How to write a code for reverse of string without using string functions?
What are linker error?
What is an array? What the different types of arrays in c?
What does the c in ctime mean?
What is array of structure in c?
Explain the use of 'auto' keyword
How can I generate floating-point random numbers?
What is a function simple definition?
What are the similarities between c and c++?
What is the purpose of main( ) in c language?
What 'lex' does?
What is c standard library?
What is auto keyword in c?
Can you define which header file to include at compile time?