解题思路:
注意事项:
参考代码:
编译错误
#include<stdio.h>
int fac(unsigned int n, int s = 0)
{
s += n % 10;
n /= 10;
if(n < 10)
{
s += n;
return s;
}
else fac(n, s);
}
int main()
{
int s = 0;
unsigned n;
while(scanf("%d", &n) != EOF)
{
printf("%d\n",fac(n, s));
}
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
char str[10];
int i, s;
while(scanf("%s", str) != EOF)
{
s = 0;
for(i = 0; str[i] != '\0'; i++)
{
s += str[i] - '0';
}
printf("%d\n", s);
}
return 0;
}
0.0分
0 人评分