本题要求编写程序,计算学生们的平均成绩,并统计不及格(成绩低于60分)的人数。题目保证输入与输出均在双精度范围内。
时间: 2023-04-29 11:04:51 浏览: 219
可以使用 C++ 或 Python 编写程序来实现题目中的要求。
C++ 示例代码:
```
#include <iostream>
using namespace std;
int main()
{
int n;
double score, sum = 0, average;
int fail = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> score;
sum += score;
if (score < 60)
{
fail++;
}
}
average = sum / n;
cout << "平均成绩为:" << average << endl;
cout << "不及格人数为:" << fail << endl;
return 0;
}
```
Python 示例代码:
```
n = int(input())
scores = list(map(float,input().split()))
sum_score = 0
fail = 0
for score in scores:
sum_score += score
if score < 60:
fail += 1
average = sum_score / n
print("平均成绩为:%.2f" % average)
print("不及格人数为:%d" % fail)
```
阅读全文