MeehoweCK

Untitled

Oct 19th, 2020
744
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. string odwrotna(string tekst)
  6. {
  7.     string wynik = "";
  8.  
  9.     for(int i = tekst.size() - 1; i >= 0; --i)
  10.     {
  11.         wynik += tekst[i];
  12.     }
  13.     return wynik;
  14. }
  15.  
  16. string suma(string a, string b)
  17. {
  18.     int wynik[10000];
  19.     bool flaga = false;
  20.     int cyfra;
  21.     unsigned i;
  22.  
  23.     a = odwrotna(a);
  24.     b = odwrotna(b);
  25.  
  26.     if(a.size() < b.size())
  27.         for(i = a.size(); i < b.size(); ++i)
  28.             a += '0';
  29.     else if(b.size() < a.size())
  30.         for(i = b.size(); i < a.size(); ++i)
  31.             b += '0';
  32.  
  33.     for(i = 0; i < a.size(); ++i)
  34.     {
  35.         cyfra = a[i] + b[i] - 96;
  36.         if(flaga)
  37.             ++cyfra;
  38.         if(cyfra > 9)
  39.         {
  40.             cyfra -= 10;
  41.             flaga = true;
  42.         }
  43.         else
  44.             flaga = false;
  45.         wynik[i] = cyfra;
  46.     }
  47.     string result = "";
  48.  
  49.     for(unsigned j = 0; j < i; ++j)
  50.         result += wynik[j] + 48;
  51.     if(flaga)
  52.         result += '1';
  53.     return odwrotna(result);
  54. }
  55.  
  56. int main()
  57. {
  58.     string a, b;
  59.     cin >> a >> b;
  60.     cout << "suma: " << suma(a, b) << endl;
  61.     cout << "roznica: " << roznica(a, b) << endl;
  62.     cout << "iloczyn: " << iloczyn(a, b) << endl;
  63.     return 0;
  64. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×