C++ 计算三位数加法进位次数
#include <iostream>
using namespace std;
int main() {
int a, b;
while(cin >> a >> b && (a != 0 || b != 0)) {
int count = 0;
int carry = 0;
while(a > 0 || b > 0) {
int digit_a = a % 10;
int digit_b = b % 10;
int sum = digit_a + digit_b + carry;
if(sum >= 10) {
count++;
carry = 1;
} else {
carry = 0;
}
a /= 10;
b /= 10;
}
cout << count << endl;
}
return 0;
}
原文地址: http://www.cveoy.top/t/topic/l1r 著作权归作者所有。请勿转载和采集!