Power Two
Check whether given number is power of Two or not.
For example: If the given number is 32 then it should return true as it is power of two.
If the given number is 3 then it should return false as it is not power of two.
For example: If the given number is 32 then it should return true as it is power of two.
If the given number is 3 then it should return false as it is not power of two.
Sol:
1
2
3
4
5
6
7
| Boolean isPowerTwo( int n) { if ( n> 0 && (n&n- 1 )== 0 ) return true ; else return false ; } |
No comments:
Post a Comment