InterviewSolution
Saved Bookmarks
| 1. |
Write a program to check if a number is a power of 2 or not. |
|
Answer» We can do this by using BITWISE operators. void main (){ int num; printf ("Enter any no:"); scanf ("%d", &num); if (num & & ((num & num-1) == 0)) printf ("NUMBER is a POWER of 2"); else printf ("Number is not a power of 2");} |
|