1350. Primary arithmetic

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.