-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumoftwobigintegers.cpp
More file actions
51 lines (40 loc) · 975 Bytes
/
Sumoftwobigintegers.cpp
File metadata and controls
51 lines (40 loc) · 975 Bytes
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
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <vector>
using namespace std;
void findsum(string a, string b) {
vector<int>sonuc;
int elde = 0;
int i = a.size() - 1, j = b.size() - 1;
while ((i >= 0) and (j >= 0)) {
int x = (a[i] - '0') + (b[j] - '0') + elde;
sonuc.push_back(x % 10);
elde= x / 10;
i--;
j--;
}
while (i >= 0) {
int x = (a[i] - '0') + elde;
sonuc.push_back(x % 10);
elde = x / 10;
i--;
}
while (j >= 0) {
int x = (b[j] - '0') + elde;
sonuc.push_back(x % 10);
elde = x / 10;
j--;
}
while (elde) {
sonuc.push_back(elde % 10);
elde = elde / 10;
}
for (int k = sonuc.size() - 1; k >= 0; k--) {
cout << sonuc[k];
}
cout <<endl;
}
int main() {
findsum("123456789098765325235252352352352352323235464645656786786744344534242346688", "324232523523346574745745645645555555555555555555555456456455457455555555555");
system("pause");
return 0;
}