-
Notifications
You must be signed in to change notification settings - Fork 0
/
Primary_Arithmetic.cc
49 lines (34 loc) · 952 Bytes
/
Primary_Arithmetic.cc
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
#include <iostream>
using namespace std;
int getCarryOps(int n1, int n2) {
int carry_count = 0, carry_num = 0;
while(n1 > 0 && n2 > 0) {
int dn1 = n1 % 10;
int dn2 = n2 % 10;
carry_num = (dn1 + dn2 + carry_num)/10;
carry_count += carry_num > 0 ? 1 : 0;
n1 = n1/10;
n2 = n2/10;
}
return carry_count;
}
int main() {
// must count the amount of carry operations, while, having a carry
int n1, n2;
int carry_count = 0;
while(cin >> n1 >> n2 && (n1 != 0 || n2 != 0)) {
carry_count = getCarryOps(n1, n2);
if(carry_count > 1)
{
cout << carry_count << " carry operations." << endl;
}
else if(carry_count == 1)
{
cout << "1 carry operation." << endl;
}
else
{
cout << "No carry operations." << endl;
}
}
}