暑假裡每天的最高溫度在陣列 temps 裡,一共 n 天。寫 hot_days(temps, n),數一數有幾天是 30 度或更熱。n 是 0 就返回 0。
hot_days({28, 31, 30, 25}, 4)→2hot_days({}, 0)→0int hot_days(int temps[], int n)int hot_days(int temps[], int n) {
int count = 0;
for (int i = 0; i < n; i++) {
// 在這裡寫:這天 30 度或更熱,count 就加 1
}
return count;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。