Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.  
  5. int iNum1 = 0, iNum2 = 0, iCountZero = 0, iCountOne = 0;
  6. const int iZero = 0, iOne = 1;
  7.  
  8. scanf_s("%d", &iNum1);
  9. iNum2 = iNum1;
  10.  
  11. for (int i = 2; i <= iNum1; i++) {
  12.  
  13. if (iNum1 <= 0)
  14. printf("Enter the num doesn`t equal 0 or less.\n");
  15.  
  16. else if (iNum1 > 0) {
  17.  
  18. while (iNum1) {
  19.  
  20. if (iNum1 % 2 == 0) {
  21. printf("%d", iZero);
  22.  
  23. if (iNum1 % 2 == 0)
  24. iCountZero++;
  25.  
  26. } else if (iNum1 % 2 == 1) {
  27. printf("%d", iOne);
  28.  
  29. if (iNum1 % 2 == 1)
  30. iCountOne++;
  31. }
  32.  
  33. iNum1 = iNum1 / 2;
  34. }
  35.  
  36. printf("\n");
  37.  
  38. if (iCountOne > iCountZero)
  39. printf("%d", iNum2);
  40. }
  41. }
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement