练琴小程序给每首曲子打分: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;
}
写好了先点「运行」试试示例,没问题再点「提交」。