题解 | 数位之和

数位之和

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);
}

注意负数

全部评论

相关推荐

03-23 23:00
黄淮学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务