Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <limits.h>
- int main()
- {
- int num;
- printf("Enter number: ");
- scanf("%d", &num);
- int flag = 0;
- //1 2 4 8 16 32 64 128 256 512 1024
- int i = 1;
- while (i <= num)
- {
- if(i == num)
- {
- flag = 1;
- break;
- }
- i*=2;
- }
- if (flag)
- {
- printf("%d is power of 2", num);
- }
- else
- {
- printf("%d is not power of 2", num);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement