本题解法
从键盘输入一个正整数n,计算该数的各位数字之和并输出。例如输入5246,计算5+2+4+6=17并输出
2020-04-05 19:46
2020-04-05 19:56
程序代码:#include <stdio.h>
int main()
{
int count = 0;
for(int n = '0'; n != '\n'; n = getchar())
count += n - '0';
printf("%d\n", count);
return 0;
}

2020-04-05 21:32

2020-04-06 00:58
程序代码:#include<stdio.h>
int main()
{
int n,sum=0;
scanf("%d",&n);
while(n)
{
sum += n%10;
n/=10;
}
printf("%d\n",sum);
return 0;
}
2020-04-06 13:40
2020-04-06 20:21
2020-04-06 20:50
程序代码:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main(void)
{
int theNum = 0;
scanf("%d", &theNum);
int theResult = 0;
while (theResult += (theNum%10),theNum /= 10) {}
printf("%d\n", theResult);
}
2020-04-09 10:58
2020-04-10 09:37
程序代码:
unsigned binary_ascii_add(unsigned value) {
unsigned quotient;
unsigned sum = 0;
quotient = value / 10;
if (0 != quotient) {
sum += binary_ascii_add(quotient);
}
sum += value % 10;
return sum;
}
2020-04-10 14:31