题解 | 数位之和
数位之和
https://www.nowcoder.com/practice/5e85cc26475449648e668aa98e92d05b
#include<stdio.h>
#include<stdlib.h>
int len_sum(long m){
long x;
x = (long)abs(m);
long a;
long b;
long temp;
long sum;
a = x%10;
b = x/10;
while(b>=10){
temp = b%10;
b = b/10;
a+=temp;
}
a+=b;
return a;
}
int main(){
long x;
int result;
scanf("%ld",&x);
result = len_sum(x);
printf("%d",result);
}
注意负数
查看19道真题和解析