解题思路:接上题,只需要加工一下就行了
注意事项:初始化不赋值的元素
参考代码:
#include#include using namespace std; typedef struct Student{ char id[32]; char name[32]; int grade[3]; }student; int main() { int N, i = 0; int indx = 0, total_points, temp = 0; int grade_average[3] = {0}; cin >> N; student *ptr = (student *)malloc(sizeof(student) * N); if(ptr == NULL) return 1; for(i = 0; i < N; i++){ cin >> ptr[i].id; cin >> ptr[i].name; cin >> ptr[i].grade[0]; cin >> ptr[i].grade[1]; cin >> ptr[i].grade[2]; grade_average[0] += ptr[i].grade[0]; grade_average[1] += ptr[i].grade[1]; grade_average[2] += ptr[i].grade[2]; total_points = ptr[i].grade[0] + ptr[i].grade[1] + ptr[i].grade[2]; if(temp < total_points) { temp = total_points; indx = i; } } cout << grade_average[0] / N << ' '; cout << grade_average[1] / N << ' '; cout << grade_average[2] / N << ' '; cout << endl; cout << ptr[indx].id << ' '; cout << ptr[indx].name << ' '; cout << ptr[indx].grade[0] << ' '; cout << ptr[indx].grade[1] << ' '; cout << ptr[indx].grade[2] << ' '; free(ptr); return 0; }
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:716 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:626 |
C语言训练-立方和不等式 (C语言代码)浏览:779 |
printf基础练习2 (C语言代码)浏览:322 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:591 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:934 |
DNA (C语言描述,蓝桥杯)浏览:1653 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:388 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:727 |
1013题解浏览:596 |