Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- cout << "Enter numbers ";
- string s1, s2, result="";
- cin >>s1;
- cin >>s2;
- char k;
- if (s1.size() < s2.size())
- {
- swap(s1, s2);
- }
- cout << endl;
- cout << s1 <<endl<< "+" <<endl << s2;
- int numeral = 0;
- int n = s2.size();
- int i;
- for (i = 0; i < n; i++)
- {
- numeral = numeral + (s1[n - 1 - i] - '0') + (s2[n - 1 - i] - '0');
- k = numeral % 10 + '0';
- result = k + result;
- numeral = numeral / 10;
- }
- n = s1.size();
- while (i < n)
- {
- numeral = numeral + (s1[n - 1 - i] - '0');
- k = numeral % 10 + '0';
- result =k+result;
- numeral = numeral / 10;
- i++;
- }
- if (numeral != 0)
- {
- k = numeral % 10 + '0';
- result = k + result;
- }
- cout << result;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment