Aleksandr_Grigoryev

сумма

Mar 8th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     cout << "Enter numbers ";
  8.     string s1, s2, result="";
  9.     cin >>s1;
  10.     cin >>s2;
  11.     char k;
  12.     if (s1.size() < s2.size())
  13.     {
  14.         swap(s1, s2);
  15.     }
  16.     cout << endl;
  17.     cout << s1 <<endl<< "+" <<endl << s2;
  18.     int numeral = 0;
  19.     int n = s2.size();
  20.     int i;
  21.     for (i = 0; i < n; i++)
  22.     {
  23.         numeral = numeral + (s1[n - 1 - i] - '0') + (s2[n - 1 - i] - '0');
  24.         k = numeral % 10 + '0';
  25.         result = k + result;
  26.         numeral = numeral / 10;
  27.     }
  28.     n = s1.size();
  29.     while (i < n)
  30.     {
  31.         numeral = numeral + (s1[n - 1 - i] - '0');
  32.         k = numeral % 10 + '0';
  33.         result =k+result;
  34.         numeral = numeral / 10;
  35.         i++;
  36.     }
  37.     if (numeral != 0)
  38.     {
  39.         k = numeral % 10 + '0';
  40.         result = k + result;
  41.     }
  42.     cout << result;
  43.     system("pause");
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment