用c语言写出输入学生信息,学生信息包括学号、姓名、平时成绩、实训成绩和期末成绩,求学生的总评成绩,并统计总成绩中及格人数和及格率。(其中:总评成绩=平时成绩的%30+实训成绩的%30+期末成绩的%40)
时间: 2023-11-27 12:54:58 浏览: 85
下面是一个简单的用 C 语言实现输入学生信息的代码示例,包括计算总评成绩和统计及格人数及及格率:
```c
#include <stdio.h>
struct Student {
int id;
char name[20];
float dailyGrade;
float practicalGrade;
float finalGrade;
float totalGrade;
};
int main() {
int num, passCount = 0;
float passRate;
printf("请输入学生人数:");
scanf("%d", &num);
struct Student students[num];
for (int i = 0; i < num; i++) {
printf("\n请输入第%d个学生的信息:\n", i+1);
printf("学号:");
scanf("%d", &students[i].id);
printf("姓名:");
scanf("%s", students[i].name);
printf("平时成绩:");
scanf("%f", &students[i].dailyGrade);
printf("实训成绩:");
scanf("%f", &students[i].practicalGrade);
printf("期末成绩:");
scanf("%f", &students[i].finalGrade);
students[i].totalGrade = students[i].dailyGrade * 0.3 + students[i].practicalGrade * 0.3 + students[i].finalGrade * 0.4;
if (students[i].totalGrade >= 60) {
passCount++;
}
}
passRate = (float)passCount / num * 100;
printf("\n总共有%d位学生:\n", num);
for (int i = 0; i < num; i++) {
printf("学号:%d,姓名:%s,总评成绩:%.2f\n", students[i].id, students[i].name, students[i].totalGrade);
}
printf("\n及格人数:%d,及格率:%.2f%%\n", passCount, passRate);
return 0;
}
```
运行程序,按照提示输入学生信息,程序会自动计算并输出每个学生的总评成绩,最后统计及格人数和及格率。
阅读全文
相关推荐
![](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)
![](https://img-home.csdnimg.cn/images/20250102104920.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.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://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)