总代码
#include <stdio.h>
#include <stdlib.h>
int tot=0;
void addto(int number){
if (number <= 0){
printf("Final:total=%d\n",tot);
tot=0;
}
else{
printf("Now total: %d=%d+%d\n",tot+number,tot,number);
tot=tot+number;
addto(number-1);
}
}
void tesksample(){
printf("10的递加:\n");
addto(10);
}
int main(){
tesksample();
return 0;
}
这就是学习运用多次的递归函数;
这是运行结果