回复:(lzmhstc)[求助]计算一个整数的各位数字之和的...
											这个程序可以连续的计算好几个数字的所有位得所有数之和,并且因为使用了长整形,所以,可以计算的数字更大。
#include "math.h"
#include "stdio.h"
int f(long int n,int sum){
   if(n/10==0)return sum+n;
    return n%10+f(n/10,sum);
}
main()
{
    long int n,sum=0;
    printf("Please input the number to end with #:\n");
    scanf("%ld",&n);
    while(n)
    {
        printf("The all number add together is :\n");
        printf("%d",f(n,sum));
        printf("\n\nPlease input 1 to exit or other to continue:");
        scanf("%ld",&n);
        if(n==1)
            {
                printf("Please press to exit...");
                getch();
                exit(0);
            }
        printf("\nPlease input the number to end with #:\n");
        scanf("%ld",&n);
    }
    getch();
}
浏览我的博客