写一段计算平均绩点的代码
时间: 2023-03-30 15:02:27 浏览: 82
以下是计算平均绩点的代码:
```
#include <stdio.h>
int main() {
int n;
scanf("%d", &n); // 输入学科数量
double sum_credit = ; // 总学分
double sum_gpa = ; // 总绩点
for (int i = ; i < n; i++) {
double credit, score;
scanf("%lf %lf", &credit, &score); // 输入学科学分和成绩
sum_credit += credit;
if (score >= 90) {
sum_gpa += 4. * credit;
} else if (score >= 85) {
sum_gpa += 3.7 * credit;
} else if (score >= 82) {
sum_gpa += 3.3 * credit;
} else if (score >= 78) {
sum_gpa += 3. * credit;
} else if (score >= 75) {
sum_gpa += 2.7 * credit;
} else if (score >= 72) {
sum_gpa += 2.3 * credit;
} else if (score >= 68) {
sum_gpa += 2. * credit;
} else if (score >= 64) {
sum_gpa += 1.5 * credit;
} else if (score >= 60) {
sum_gpa += 1. * credit;
}
}
printf("%.2lf", sum_gpa / sum_credit); // 输出平均绩点
return ;
}
```
相关推荐
![exe](https://img-home.csdnimg.cn/images/20210720083343.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![m](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)