Kodewick
開始學 →
基礎←→0 / 70

練琴得星星

#063基礎約 5 分鐘

練琴小程式給每首曲子打分:90 分及以上 3 顆星,70 及以上 2 顆,50 及以上 1 顆,再低沒有。寫 stars_earned(scores, n),算 n 首一共幾顆星。沒有曲子返回 0。

示例
stars_earned({95, 72, 40}, 3)→5
stars_earned({50}, 1)→1
函式int stars_earned(int scores[], int n)
main.c
int stars_earned(int scores[], int n) {
    int stars = 0;
    for (int i = 0; i < n; i++) {
        // 在這裡寫:按這首的分數,給 stars 加 3、2、1 或不加
    }
    return stars;
}
Ctrl + Enter 也能執行
結果

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