做的不好
程序代码:
#include<stdio.h> void input(char(*p_course)[10], int *p_num, float *p_score) { int i, j; printf("Please input student's number:\n"); for (i = 0; i < 4; i++) scanf_s("%d", p_num + i); printf("Please input student's course:\n"); for (j = 0; j < 5; j++) scanf_s("%s", p_course[j], 10); printf("Please input student's score:\n"); for (i = 0; i < 4; i++) for (j = 0; j < 5; j++) scanf_s("%f", p_score + 5 * i + j); } void aver_score(float *p_score, float *p_aver) { int i, j; float sum, aver; for (i = 0; i < 4; i++) { sum = 0; aver = 0; for (j = 0; j < 5; j++) sum += *(p_score + 5 * i + j); aver = sum / 5; *(p_aver + i) = aver; } } void aver_course(char(*p_course)[10], float *p_score) { int i; float sum = 0, aver; for (i = 0; i < 4; i++) sum += *(p_score + 5 * i); aver = sum / 4; printf("course 1:%s average score is %5.2f\n", *p_course, aver); } void fail_score(char(*p_course)[10], int *p_num, float *p_score, float *p_aver) { int i, j, k; printf(" ==============Student who is failed in two courses============= \n"); printf("No. "); for (i = 0; i < 5; i++) printf("%11s", p_course[i]); printf(" average\n"); for (i = 0; i < 4; i++) { k = 0; for (j = 0; j < 5; j++) if (*(p_score + 5 * i + j) < 60) k++; if (k >= 2) { printf("%d", p_num[i]); for (j = 0; j < 5; j++) printf("%11.2f", *(p_score + 5 * i + j)); printf("%11.2f\n", p_aver[i]); } } } void good_score(char(*p_course)[10], int *p_num, float *p_score, float *p_aver) { int i, j, n; printf(" ===============Student whose score is good============ \n"); printf("No. "); for (i = 0; i < 5; i++) printf("%11s", p_course[i]); printf(" average\n"); for (i = 0; i < 4; i++) { n = 0; for (j = 0; j < 5; j++) if (*(p_score + 5 * i + j) > 85) n++; if (n == 5 || p_aver[i] > 90) { printf("%d", p_num[i]); for (j = 0; j < 5; j++) printf("%11.2f", *(p_score + 5 * i + j)); printf("%11.2f\n", p_aver[i]); } } } int main() { void input(char(*p_course)[10], int *p_num, float *p_score); void aver_score(float *p_score, float *p_aver); void aver_course(char(*p_course)[10], float *p_score); void fail_score(char(*p_course)[10], int *p_num, float *p_score, float *p_aver); void good_score(char(*p_course)[10], int *p_num, float *p_score, float *p_aver); char course[5][10], (*p_course)[10]; int num[4], *p_num; float score[4][5], *p_score, aver[4], *p_aver; p_course = course; p_num = num; p_score = *score; p_aver = aver; input(p_course, p_num, p_score); aver_score(p_score, p_aver); aver_course(p_course, p_score); fail_score(p_course, p_num, p_score, p_aver); good_score(p_course, p_num, p_score, p_aver); return 0; }