#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int sum(int s, int e){
//遞增,s是定值
if(s==e){
return e;
}else{
// 2 ->3 ->4 ->5
return sum(s+1, e)+s;
}
}
int main(int argc, char *argv[]) {
int start, end;
printf("輸入start:");
scanf("%i", &start);
printf("輸入end:");
scanf("%i", &end);
printf("%i", sum(start, end) );
return 0;
return 0;
}
沒有留言:
張貼留言