Guest User

Untitled

a guest
Jan 24th, 2018
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5.  
  6. string dodawanie(string liczba1_temp, string liczba2_temp)
  7. {
  8.         string wynik, reszta;
  9.         wynik =   "0000000000000000000000000000000000000000000000000000000000000000";
  10.         reszta =  "0";
  11.  
  12.         for(int x=63; x>-1;x--)
  13.         {
  14.                 if((liczba1_temp[x] == '0' && liczba2_temp[x] == '1' && reszta[0]=='0') || (liczba1_temp[x] == '1' && liczba2_temp[x] == '0' && reszta[0]=='0'))
  15.                 {
  16.                         wynik[x] = '1';
  17.                         reszta[0] = '0';
  18.                 }
  19.                 else if((liczba1_temp[x] == '0' && liczba2_temp[x] == '1' && reszta[0]== '1') || (liczba1_temp[x] == '1' && liczba2_temp[x] == '0' && reszta[0]=='1'))
  20.                 {
  21.                         wynik[x] = '0';
  22.                         reszta[0] = '1';
  23.                 }
  24.                 else if(liczba1_temp[x] == '0' && liczba2_temp[x] == '0' && reszta[0] =='0')
  25.                 {
  26.                         wynik[x] = '0';
  27.                         reszta[0] = '0';
  28.                 }
  29.                 else if(liczba1_temp[x] == '0' && liczba2_temp[x] == '0' && reszta[0] =='1')
  30.                 {
  31.                         wynik[x] = '1';
  32.                         reszta[0] = '0';
  33.                 }
  34.                 else if(liczba1_temp[x] == '1' && liczba2_temp[x] == '1' && reszta[0] == '0')
  35.                 {
  36.                         wynik[x] = '0';
  37.                         reszta[0] = '1';
  38.                 }
  39.                 else if(liczba1_temp[x] == '1' && liczba2_temp[x] == '1' && reszta[0] =='1')
  40.                 {
  41.                         wynik[x] = '1';
  42.                         reszta[0] = '1';
  43.                 }
  44.         }
  45.         return wynik;
  46. }
  47.  
  48. int main()
  49. {
  50.         string l1, l2, liczba1, liczba2;
  51.         int dlugosc1, dlugosc2, wybor;
  52.  
  53.         liczba1 = "0000000000000000000000000000000000000000000000000000000000000000";
  54.         liczba2 = "0000000000000000000000000000000000000000000000000000000000000000";
  55.  
  56.         cout << "Podaj liczbe 1: ";
  57.         cin >> l1;
  58.         dlugosc1 = l1.length();
  59.         cout << "Podaj liczbe 2:";
  60.         cin >> l2;
  61.         dlugosc2 = l2.length();
  62.        
  63.  
  64.         for(int x=dlugosc1-1; x>-1; x--)
  65.         {
  66.                 liczba1[63-x] = l1[dlugosc1-1-x];
  67.         }
  68.  
  69.         for(int x=dlugosc2-1; x>-1; x--)
  70.         {
  71.                 liczba2[63-x] = l2[dlugosc2-1-x];
  72.         }
  73.                
  74.    
  75.     cout << dodawanie(liczba1, liczba2);
  76.  
  77.         getchar();
  78.        
  79. }
Add Comment
Please, Sign In to add comment