每年生日的蛋糕上,几岁就插几根蜡烛。写 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;
}
写好了先点「运行」试试示例,没问题再点「提交」。