C语言:用递归函数DigitSum(n)实现输入1729,输出sum=1+7+2+9=19的值
程序员文章站
2022-08-09 18:11:49
#define _crt_secure_no_warnings
#include
#include
int digitsum(...
#define _crt_secure_no_warnings #include<stdio.h> #include<stdlib.h> int digitsum(unsigned int num) { int sum = 0; int n = 0; if (num != 0) { n = num % 10; num = num / 10; sum = n + digitsum(num); } return sum; } int main() { unsigned int num = 1729; printf("%d\n", digitsum(num)); system("pause"); return 0; }
上一篇: ios之导航渐变---/导航透明