#include<stdio.h> int DigitSum(unsigned int n) { int num = 0; if( n == 0) { return num; } else num = n%10; n /= 10; return num + DigitSum(n); } int main() { unsigned int n = 0; int ret = 0; printf("请输入一个非负整数:"); scanf("%d",&n); ret = DigitSum(n); printf("%d\n",ret); return 0; }
时间: 2024-10-20 21:33:48