Function to find the given number is a power of 2 or not?
Answer Posted / anyone
//Revision for Ahmed Ihmeid answer:
//Operator % prototype: int % int
bool isPowerOf2(int num)
{
int x;
x = num % (int(ceil(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 % 5 != 0
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
Is c call by value?
What is a buffer in c?
How to throw some light on the b tree?
What is floating point constants?
What is volatile variable in c with example?
What is the difference between struct and union in C?
Explain is it valid to address one element beyond the end of an array?
What is unsigned int in c?
What is && in c programming?
Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented Input: 11:30 Output: 13:10 Input: 18:25 Output: 21:58
#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }
Is int a keyword in c?
In a byte, what is the maximum decimal number that you can accommodate?
hi send me sample aptitude papers of cts?
When should I declare a function?