Advertisement
Guest User

Untitled

a guest
May 24th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. char sr1[65], sr2[65], sr3[73];
  6. char *p1=sr1, *p2=sr2, *p3=sr3, *k1=sr1, *k2=sr2, *k3=sr3;
  7.  
  8. int check, length = 0, i;
  9.  
  10. while (1)
  11. {
  12. for (i = 0; i < length; i++)
  13. {
  14. sr1[i] = '\0';
  15. }
  16.  
  17. p1 = sr1;
  18.  
  19. check = 0;
  20.  
  21. printf("Ведіть перший двійковий код цілого беззнакового числа:\n");
  22. fgets(sr1, 64, stdin);
  23.  
  24. while (*p1)
  25. {
  26. if (*p1 != '0' && *p1 != '1' && *p1 != '\n')
  27. check = 1;
  28.  
  29. p1++;
  30. length++;
  31. }
  32.  
  33. if (!check)
  34. break;
  35. }
  36.  
  37. p1 = p1 - 2;
  38. k1 = p1;
  39. length = 0;
  40.  
  41. while (1)
  42. {
  43.  
  44. for (i = 0; i < length; i++)
  45. {
  46. sr2[i] = '\0';
  47. }
  48.  
  49. p2 = sr2;
  50.  
  51. check = 0;
  52.  
  53. printf("Ведіть другий двійковий код цілого беззнакового числа:\n");
  54. fgets(sr2, 64, stdin);
  55.  
  56. while (*p2)
  57. {
  58. if (*p2 != '0' && *p2 != '1' && *p2 != '\n')
  59. check = 1;
  60.  
  61. p2++;
  62. length++;
  63. }
  64.  
  65. if (!check)
  66. break;
  67. }
  68.  
  69. p2 = p2 - 2;
  70. k2 = p2;
  71.  
  72. int firstNum, secondNum, thirdNum, temp;
  73.  
  74. printf("%-10s%-10s%-10s\n", "Pershe", "Druhe", "Trete");
  75.  
  76. while (p1 >= sr1 && p2 >= sr2)
  77. {
  78. firstNum = *p1 - '0';
  79. secondNum = *p2 - '0';
  80. thirdNum = firstNum + secondNum;
  81.  
  82. printf("%-10d %-10d %-10d\n", firstNum, secondNum, thirdNum);
  83.  
  84. if(*p3 == NULL)
  85. *p3 = thirdNum + '0';
  86. else
  87. {
  88. temp = *p3 - '0';
  89. thirdNum += temp;
  90. *p3 = thirdNum + '0';
  91. }
  92.  
  93. if (*p3 == '2')
  94. {
  95. *(p3+1) = '1';
  96. *p3 = '0';
  97. }
  98.  
  99. if (*p3 == '3')
  100. {
  101. *p3 = '1';
  102. *(p3+1) = '1';
  103. }
  104.  
  105.  
  106.  
  107. p1--;
  108. p2--;
  109. p3++;
  110.  
  111. }
  112.  
  113. if(*p3 == NULL)
  114. p3--;
  115.  
  116. while(*p3)
  117. putchar(*p3--);
  118.  
  119. return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement