解题思路:接上题,只需要加工一下就行了
注意事项:初始化不赋值的元素
参考代码:
#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语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:789 |
简单的a+b (C语言代码)浏览:543 |
【明明的随机数】 (C语言代码)浏览:816 |
1054题解浏览:479 |
1035 题解浏览:829 |
剪刀石头布 (C++代码)浏览:1739 |
局部变量作函数返回值的问题浏览:992 |
蓝桥杯历届试题-翻硬币 (C++代码)浏览:895 |
陶陶摘苹果2 (C语言代码)浏览:608 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:700 |