1949: Elementary school mathematics

1949: Elementary school mathematics

Title Description
Many elementary school students find that "carry" is particularly prone to errors when learning addition. Your task is to calculate how many rounds are needed to add two three-digit numbers.
Input
Input two positive integers m, n. (m, n, both are three digits).
Output
output m, n, how many times do you need to carry when adding.
Sample input
123 456
Sample output
0

#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
    
    
    int a,b,m,n,k=0,t=0;
    scanf("%d%d",&m,&n);
    while(m*n)
    {
    
    
        a=m%10;//取m和n的末位数
        b=n%10;
        if(a+b+k>=10)
        {
    
    
            k=(a+b)/10;//计算进的数
            t++;//计算进的次数
        }
        else k=0;//防止干扰下次计算
        n=n/10,m=m/10;
    }
    printf("%d",t);
}

Guess you like

Origin blog.csdn.net/weixin_51996479/article/details/111350226