Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7. char pribav(char *array, int n) {
  8. for (int i = n - 1; i > 0; i--) {
  9. if (array[i] == '0') {
  10. array[i] = '1';
  11. break;
  12. }
  13. else {
  14. array[i] = '0';
  15. }
  16. }
  17. return *array;
  18. }
  19.  
  20. int main()
  21. {
  22. SetConsoleCP(1251);
  23. SetConsoleOutputCP(1251);
  24. const int n = 8;
  25. char pr[n + 1] = "";
  26. cout << "Введите восьмиразрядное число в прямом коде ";
  27. cin >> pr;
  28. if (pr[0] == '1') {
  29. //инвертируем значение
  30. for (int i = 1; i < n; i++) {
  31. if (pr[i] == '1')
  32. pr[i] = '0';
  33. else
  34. pr[i] = '1';
  35. }
  36. //прибавляем единицу
  37. pribav(pr, n);
  38. }
  39. cout << "Число в дополнительном коде "<< pr;
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement