Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <windows.h>
- using namespace std;
- char pribav(char *array, int n) {
- for (int i = n - 1; i > 0; i--) {
- if (array[i] == '0') {
- array[i] = '1';
- break;
- }
- else {
- array[i] = '0';
- }
- }
- return *array;
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- const int n = 8;
- char pr[n + 1] = "";
- cout << "Введите восьмиразрядное число в прямом коде ";
- cin >> pr;
- if (pr[0] == '1') {
- //инвертируем значение
- for (int i = 1; i < n; i++) {
- if (pr[i] == '1')
- pr[i] = '0';
- else
- pr[i] = '1';
- }
- //прибавляем единицу
- pribav(pr, n);
- }
- cout << "Число в дополнительном коде "<< pr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement