#include
int getsum(int num);
int main(void) {
printf("The sum is: %d\n", getsum(100));
return 0;
}
int getsum(int num) {
if (num <= 0) return 0;
else if (num % 2 == 0) return num + getsum(num - 2);
else return getsum(num - 1);
}
这个题目太有意思了,明明不用递归更好看……
#include
int sum(int x)
{
if(x==2) return x;
else return sum(x-2)+x;
}
int main()
{
printf("%d",sum(100));
return 0;
}