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
Who invented b language?
What are the types of i/o functions?
How can you find out how much memory is available?
Why header file is used in c?
Explain the use of 'auto' keyword in c programming?
How can I find the modification date and time of a file?
What is getch () for?
How would you rename a function in C?
Explain logical errors? Compare with syntax errors.
In a byte, what is the maximum decimal number that you can accommodate?
Which header file should you include if you are to develop a function which can accept variable number of arguments?
What is 2c dna?
What do mean by network ?
If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.
How do you define structure?