// 用递归法求1~100的和
#include <stdio.h>
unsigned int my_sum(unsigned int n)
{
if (n <= 0)
return 0;
if (n == 1)
return 1;
else
return n + my_sum(n-1);
}
int main()
{
int a = my_sum(100);
printf ("%d\n", a);
return 0;
}
递归法求和.c
最新推荐文章于 2022-11-09 22:12:05 发布