请你用c语言编写一个程序,使得能够输入的学生成绩,统计60分以上的人数,并计算出平均分
时间: 2023-04-02 21:04:02 浏览: 173
你好,以下是我的回答:
```
#include <stdio.h>
int main() {
int score, count = , sum = ;
float average;
printf("请输入学生成绩:\n");
while (scanf("%d", &score) == 1) {
if (score >= 60) {
count++;
sum += score;
}
}
average = (float)sum / count;
printf("60分以上的人数为:%d\n", count);
printf("平均分为:%.2f\n", average);
return ;
}
```
希望能够帮到您!
相关问题
使用C语言编写一个程序,输入学生人数和每个人的成绩,计算平均成绩。
好的,这是一个计算平均成绩的问题,可以使用C语言编写一个程序来解决。以下是一个简单的程序示例:
#include <stdio.h>
int main() {
int n; // 学生人数
float grade, sum = , avg; // 成绩、总分、平均分
printf("请输入学生人数:");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
printf("请输入第%d个学生的成绩:", i);
scanf("%f", &grade);
sum += grade;
}
avg = sum / n;
printf("平均成绩为:%.2f\n", avg);
return ;
}
这个程序会提示用户输入学生人数,然后依次输入每个学生的成绩,最后计算平均成绩并输出。注意,这里使用了浮点数来存储成绩和平均成绩,以保证精度。
用C语言编写程序,实现从键盘输入10个学生的成绩,计算出平均分,并输出低于平均分的学生成绩
您好,我可以回答这个问题。以下是C语言代码实现:
#include <stdio.h>
int main() {
int scores[10]; // 存储学生成绩的数组
int sum = ; // 所有成绩的总和
float avg; // 平均分
// 从键盘输入10个学生的成绩
for (int i = ; i < 10; i++) {
printf("请输入第%d个学生的成绩:", i+1);
scanf("%d", &scores[i]);
sum += scores[i];
}
// 计算平均分
avg = (float)sum / 10;
// 输出低于平均分的学生成绩
printf("低于平均分的学生成绩为:\n");
for (int i = ; i < 10; i++) {
if (scores[i] < avg) {
printf("%d ", scores[i]);
}
}
printf("\n");
return ;
}
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)