Advertisement
TsetsoP

day1_zad5

Jul 6th, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <limits.h>
  3.  
  4. int main()
  5. {
  6. int num;
  7. printf("Enter number: ");
  8. scanf("%d", &num);
  9. int flag = 0;
  10. //1 2 4 8 16 32 64 128 256 512 1024
  11. int i = 1;
  12. while (i <= num)
  13. {
  14. if(i == num)
  15. {
  16. flag = 1;
  17. break;
  18. }
  19. i*=2;
  20. }
  21. if (flag)
  22. {
  23. printf("%d is power of 2", num);
  24. }
  25. else
  26. {
  27. printf("%d is not power of 2", num);
  28. }
  29.  
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement