fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. long long a,b;
  6.  
  7. while(cin >> a >> b)
  8. {
  9. if(a == 0 && b == 0)
  10. {
  11. break;
  12. }
  13.  
  14. int carry = 0;
  15. int carry_count = 0;
  16.  
  17. while(a>0||b>0)
  18. {
  19. int sum = a%10 + b%10 + carry;
  20. if(sum >= 10)
  21. {
  22. carry = 1;
  23. carry_count++;
  24. }
  25. else
  26. {
  27. carry = 0;
  28. }
  29. a = a/10;
  30. b = b/10;
  31. }
  32. if(carry_count == 0)
  33. {
  34. cout << "No carry operation.\n";
  35. }
  36. else if(carry_count == 1)
  37. {
  38. cout << "1 carry operation.\n";
  39. }
  40. else
  41. {
  42. cout << carry_count <<" carry operation.\n";
  43. }
  44.  
  45. }
  46. return 0;
  47. }
Success #stdin #stdout 0s 5324KB
stdin
123 456
555 555
123 594
0 0
stdout
No carry operation.
3 carry operation.
1 carry operation.