输入一个3位正整数,将其每一位的数字相加,输出和。
输入格式:
输入一个3位正整数。
变量数据类型为unsigned。
输出格式:
输出整数每一位相加后的整数和。
输入样例:
123
输出样例:
6
代码长度限制16 KB
时间限制400 ms
内存限制64 MB
参考代码:
#include <stdio.h>
int main()
{
int x,a,b,c,s;
scanf("%d",&x);
a=x/100;
b=(x-a*100)/10;
c=(x-a*100-b*10);
s=a+b+c;
printf("%d",s);
return 0;
}