今天是練習cpe的Primary Arithmetic題目
#include <iostream>
using namespace std;
int main()
{
int x , y;
while (cin >> x >> y)
{
int carry=0;
int tmp=0;
int count=0;
if(x == 0 && y == 0)
{
break;
}
while( x > 0 || y > 0)
{
tmp = x % 10 + y % 10 + carry;
if(tmp >= 10)
{
carry = tmp / 10;
count++;
}
else
{
carry = 0;
}
x /= 10;
y /= 10;
}
if(count == 0)
{
cout << "No carry operation." << endl;
}
else if(count == 1)
{
cout << count << " " << "carry operation." << endl;
}
else
{
cout << count << " " << "carry operations." << endl;
}
}
return 0;
}
##解題方向