Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void plus (char *rez1, char *rez2, char *result, int len, int len1, int len2)
- {
- int first = len1 - 1;
- int second = len2 - 1;
- int res = len - 1;
- // int memoryRes = res;
- char memory = '0';
- for (; res >-1; first --, second --, res --)
- {
- if (memory == '1')
- {
- /*if (rez1 [first] == '1' || rez2 [second] == '1')
- {
- if (rez1 [first] == '1' && rez2 [second] == '1')
- result [res] = '1';
- else
- result [res] = '0';
- memory = '1';
- }
- else
- result [res] = '1';
- memory = '0';*/
- if (rez1 [first] == '1' && rez2 [second] == '1')
- {
- result [res] = '1';
- //memory = '1';
- }
- if (rez1 [first] == '1' || rez2 [second] != '1')
- {
- result [res] = '0';
- // memory = '1';
- }
- if (rez1 [first] != '1' || rez2 [second] == '1')
- {
- result [res] = '0';
- // memory = '1';
- }
- if (rez1 [first] == '0' && rez2 [second] == '0')
- {
- result [res] = '1';
- memory = '0';
- }
- }
- else
- {
- if (rez1 [first] == '1' && rez2 [second] == '1')
- {
- result [res] = '0';
- memory = '1';
- }
- if (rez1 [first] == '1' || rez2 [second] != '1')
- {
- result [res] = '1';
- // memory = '0';
- }
- if (rez1 [first] != '1' || rez2 [second] == '1')
- {
- result [res] = '1';
- // memory = '0';
- }
- if (rez1 [first] == '0' && rez2 [second] == '0')
- {
- result [res] = '0';
- // memory = '0';
- }
- /*if (rez1 [first] == '1' || rez2 [second] == '1')
- {
- if (rez1 [first] == '1' && rez2 [second] == '1')
- result [res] = '0';
- memory = '1';
- else result [res] = '1';
- }
- else result [res] = '0';*/
- }
- }
- if (result [0] != '0' && result [0] != '1') { result [0] = '0'; }
- /* int k;
- for (k = 0; result [k] == '0' || result [k] == '1'; k++);
- result [k] = '\0';*/
- for (int i = len-1; i > -1; i--)
- {
- cout << result[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement