Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string dodawanie(string liczba1_temp, string liczba2_temp)
- {
- string wynik, reszta;
- wynik = "0000000000000000000000000000000000000000000000000000000000000000";
- reszta = "0";
- for(int x=63; x>-1;x--)
- {
- if((liczba1_temp[x] == '0' && liczba2_temp[x] == '1' && reszta[0]=='0') || (liczba1_temp[x] == '1' && liczba2_temp[x] == '0' && reszta[0]=='0'))
- {
- wynik[x] = '1';
- reszta[0] = '0';
- }
- else if((liczba1_temp[x] == '0' && liczba2_temp[x] == '1' && reszta[0]== '1') || (liczba1_temp[x] == '1' && liczba2_temp[x] == '0' && reszta[0]=='1'))
- {
- wynik[x] = '0';
- reszta[0] = '1';
- }
- else if(liczba1_temp[x] == '0' && liczba2_temp[x] == '0' && reszta[0] =='0')
- {
- wynik[x] = '0';
- reszta[0] = '0';
- }
- else if(liczba1_temp[x] == '0' && liczba2_temp[x] == '0' && reszta[0] =='1')
- {
- wynik[x] = '1';
- reszta[0] = '0';
- }
- else if(liczba1_temp[x] == '1' && liczba2_temp[x] == '1' && reszta[0] == '0')
- {
- wynik[x] = '0';
- reszta[0] = '1';
- }
- else if(liczba1_temp[x] == '1' && liczba2_temp[x] == '1' && reszta[0] =='1')
- {
- wynik[x] = '1';
- reszta[0] = '1';
- }
- }
- return wynik;
- }
- int main()
- {
- string l1, l2, liczba1, liczba2;
- int dlugosc1, dlugosc2, wybor;
- liczba1 = "0000000000000000000000000000000000000000000000000000000000000000";
- liczba2 = "0000000000000000000000000000000000000000000000000000000000000000";
- cout << "Podaj liczbe 1: ";
- cin >> l1;
- dlugosc1 = l1.length();
- cout << "Podaj liczbe 2:";
- cin >> l2;
- dlugosc2 = l2.length();
- for(int x=dlugosc1-1; x>-1; x--)
- {
- liczba1[63-x] = l1[dlugosc1-1-x];
- }
- for(int x=dlugosc2-1; x>-1; x--)
- {
- liczba2[63-x] = l2[dlugosc2-1-x];
- }
- cout << dodawanie(liczba1, liczba2);
- getchar();
- }
Add Comment
Please, Sign In to add comment