#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); string a, b, result = ""; cin >> a >> b; short int pom = 0, i = 0; // dodawanie pisemne while (max(a.size(), b.size()) >= i) { short int sum = pom; // dodaje do siebie liczby if (a.size() > i) sum += int(a[a.size() - 1 - i]) % 48; if (b.size() > i) sum += (b[b.size() - 1 - i]) % 48; pom = sum / 10; if (max(a.size(), b.size()) == i) if (sum % 10 == 0) break; result += char(sum % 10 + 48); i++; } // wypisywanie wyniku for (int i = result.size() - 1; i >= 0; i--) { cout << result[i]; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); string a, b, result = ""; cin >> a >> b; short int pom = 0, i = 0; // dodawanie pisemne while (max(a.size(), b.size()) >= i) { short int sum = pom; // dodaje do siebie liczby if (a.size() > i) sum += int(a[a.size() - 1 - i]) % 48; if (b.size() > i) sum += (b[b.size() - 1 - i]) % 48; pom = sum / 10; if (max(a.size(), b.size()) == i) if (sum % 10 == 0) break; result += char(sum % 10 + 48); i++; } // wypisywanie wyniku for (int i = result.size() - 1; i >= 0; i--) { cout << result[i]; } return 0; } |