解题思路:
注意事项:
参考代码:
编译错误
#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 人评分
C语言训练-计算:t=1-1/(2*2)-1/(3*3)-...-1/(m*m) (C语言代码)浏览:780 |
【绝对值排序】 (C语言代码)浏览:713 |
【偶数求和】 (C语言代码)浏览:639 |
C语言程序设计教程(第三版)课后习题6.6 (C++代码)浏览:624 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:534 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:667 |
矩阵加法 (C语言代码)浏览:1720 |
字符逆序 (C语言代码)浏览:612 |
永远的丰碑 (C语言代码)浏览:516 |
C二级辅导-统计字符 (C语言代码)浏览:627 |