Children is taught to add multi-digit numbers from right-to-left one digit at a time. Many find the "carry" operation-in which a 1 is carried from one digit position to being added to the next-to be a signif Icant Challenge. Your job is to count the number of carry operations for each of a set of addition problems so this educators may assess t Heir difficulty.
Each line of input contains, unsigned integers less than digits. The last line of input contains 0 0. For each line of input except the last you should compute and print the number of carry operations this would result from Adding the numbers, in the format shown below.
Sample Input
123 456555 555123) 5940 0
Output for Sample Input
No carry operation.3 carry Operations.1 carry operation.
#include <iostream>#include<cmath>using namespacestd;intMain () {unsignedintM,n,sum,i; //cin>>m>>n; while(cin>>m>>N) {if(m==0&&n==0) Break; unsignedinttemp; if(m<N) {temp=m; M=N; N=temp; } unsignedintm1,n1; I=0; Sum=0; while(m>0) {M1=m%Ten; N1=n%Ten; if(m1+n1+i>=Ten) {i=1; Sum++; } Else{i=0; } m=m/Ten; N=n/Ten; } while(n>0) { if(n%Ten+i>=Ten) {i=1; Sum++; } Else{i=0; } N=n/Ten; } if(sum==0) {cout<<"No carry operation."<<Endl; } Else if(sum==1) {cout<<sum<<"carry operation."<<Endl; } Else if(sum>1) {cout<<sum<<"carry operations."<<Endl; } //cin>>m>>n; } return 0;}
View Code
1350. Primary arithmetic