解题思路:
输入的数%10取出最低位,然后/10去掉最低位,然后OK了
注意事项:要用long long!!!!!!!!!!!!!!!!!!
参考代码:
#include<stdio.h>
#include<math.h>
int main(){
long long x,y,sum=0;
while (scanf("%lld", &x) != EOF){
for (int i = 0;; i++){
y = x % 10;
x /= 10;
sum += y;
if (x == 0){
printf("%lld\n", sum);
break;
}
}
sum = 0;
}
}
0.0分
0 人评分