Q8. Write a code to find whether a number is power of two or not

Power of Two :- we knoe that a power of two is a number of the form 2^n where n is an integer.
For Example :-
Input = 128
Output = 128 is the power of 2
So as we can see that 2^7 = 128. So the number 128 is the power of two.

Logic : Here we use a mathematical concept of Logarithm, The most simple method for finding whether a no is power of two or not is to simply take the log of the number on base 2 and if you get an integer then the number is the power of 2.

There is Following Algorithm to find whether a number is power of two or not

START
Step 1 → Take integer variable num
Step 2 → find out the log number with base 2
Step 3 → if outcome is integer then DISPLAY number is power of 2.
Step 4 → Otherwise, DISPLAY number is not power of 2.
STOP

There is Following Code to find whether a number is power of two or notr

Output

128 is the power of two.

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number