用递归方法求1+2+3+4+…+n
#include <stdio.h>
int sum_of_n(int n)
{
if (n == 1)
{
return 1;
}
return n + sum_of_n(n - 1);
}
int main()
{
int n = 0;
scanf("%d",&n);
int sum = sum_of_n(n);
printf("%d\n",sum);
return 0;
}