練琴小程式給每首曲子打分:90 分及以上 3 顆星,70 及以上 2 顆,50 及以上 1 顆,再低沒有。寫 stars_earned(scores, n),算 n 首一共幾顆星。沒有曲子返回 0。
stars_earned({95, 72, 40}, 3)→5stars_earned({50}, 1)→1int stars_earned(int scores[], int n)int stars_earned(int scores[], int n) {
int stars = 0;
for (int i = 0; i < n; i++) {
// 在這裡寫:按這首的分數,給 stars 加 3、2、1 或不加
}
return stars;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。