Q7. How to find in one line whether a given number is power of 2 or not?
It seems difficult question for them, who have encountered these type of earlier. This type of question checks your understandings of bitwise and logical operators. See solution below.
if( num && (num & (num – 1)))
printf(“Number is not the power of two\n”);
printf(“Number is the power of two\n”);
There is may be some good solution, if you have please post here.