一道ACM的题目。计算一个正整数的各位和。

来源:百度知道 编辑:UC知道 时间:2024/06/23 12:23:23
09年3月选拔赛第2题

Time Limit:JAVA/Others2000/1000MS Memory Limit:JAVA/Others131072/65536KB
Total Submit:899 Accepted:117

Description

A student of ahu Computer Science & Technology School named CQ wants to make a interesting work.He wants to calculate the sum of a positive integer that anyone gives to him.Please write a program to do this work.

Input

输入若干行,每行代表一个需要求和的正整数
最后一行为0,表示输入结束

Output

输出若干行,每行代表对应数值的求和结果。

Sample Input

123
234
12
0
Sample Output

6
9
3

我的程序提交的时候总是wrong answer,请哪位高手指点下,程序如下:
#include <stdio.h>
long int num;
int sum(num)
{
int k=0;
do{
k+=num%10;
num=num/10;
}while(num);
return k;
}
int main()
{ long int n;
while (scanf("%d",&n)&&n>0)
printf(&qu

格式没对,是发上来粘贴错了还是怎么了??
把输入和循环分开写试试,格式要求太严格了!

大数 ?

用字符串读入。。。。
肯定会输入78678678678678678678这么长的数的。

大数!
题目没说输入一定在长整范围之内,需要考虑非常大的数,比如什么1234567890123456789012345678901234567890之类的