Function to find the given number is a power of 2 or not?
Answer Posted / ahmed ihmeid
bool isPowerOf2(int num)
{
float x;
x = num % (sqrt(num));
if( x == 0)
return true; //it is a power of 2
else
return false; //it is not
}
proof:
4 % 2 = 0
16 % 4 = 0
22 % 4.7 != 0
| Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
What are the 4 data types?
what is bit rate & baud rate? plz give wave forms
why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???
What does node * mean?
What is mean by Data Driven framework in QTP? Can any one answer me in details on this regard.
What is the size of enum in bytes?
Disadvantages of C language.
What is the purpose of & in scanf?
Why do we use return in c?
How can I access an I o board directly?
#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }
Is anything faster than c?
Can we assign string to char pointer?
What is the argument of a function in c?
What is the difference between array_name and &array_name?