每年生日的蛋糕上,幾歲就插幾根蠟燭。寫 total_candles(age),算從 1 歲到 age 歲一共用了多少根。age 是 0 就是 0 根。
total_candles(3)→6total_candles(1)→1int total_candles(int age)int total_candles(int age) {
int total = 0;
for (int year = 1; year <= age; year++) {
// 在這裡寫:把這一年的蠟燭加到 total 上
}
return total;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。