2017.10.24

小学生算术

时间限制:3000 ms  |  内存限制:65535 KB
难度:1
 
描述
很多小学生在学习加法时,发现“进位”特别容易出错。你的任务是计算两个三位数在相加时需要多少次进位。你编制的程序应当可以连续处理多组数据,直到读到两个0(这是输入结束标记)。
 
输入
输入两个正整数m,n.(m,n,都是三位数)
输出
输出m,n,相加时需要进位多少次。
样例输入
123 456
555 555
123 594
0 0
样例输出
0
3 
1


#include <iostream>
#include <stdio.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv)
{
int n,m;
int count=0;
int a1[3];
int a2[3];
int array1[100];
int array2[100];
int i=0;
do
{
scanf("%d",&n);
scanf("%d",&m);
array1[i]=n;
array2[i]=m;
i++;
}while(n!=0&&m!=0);

for(int j=0;j<i-1;j++)
{
a1[0]=array1[j]/100;
a1[1]=array1[j]/10%10;
a1[2]=array1[j]%10;

a2[0]=array2[j]/100;
a2[1]=array2[j]/10%10;
a2[2]=array2[j]%10;

if(a1[0]+a2[0]>9)
count++;
if(a1[1]+a2[1]>9)
count++;
if(a1[2]+a2[2]>9)
count++;
printf("%d ",count);
count=0;
}
return 0;
}


原文地址:https://www.cnblogs.com/panlangen/p/7726317.html