Kodewick
開始學 →
入門←→0 / 70

生日蠟燭

#024入門total += year約 3 分鐘

每年生日的蛋糕上,幾歲就插幾根蠟燭。寫 total_candles(age),算從 1 歲到 age 歲一共用了多少根。age 是 0 就是 0 根。

示例
total_candles(3)→6
total_candles(1)→1
函式int total_candles(int age)
main.c
int total_candles(int age) {
    int total = 0;
    for (int year = 1; year <= age; year++) {
        // 在這裡寫:把這一年的蠟燭加到 total 上
    }
    return total;
}
Ctrl + Enter 也能執行
結果

寫好了先點「執行」試試示例,沒問題再點「提交」。