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 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。