user-0 提问: 求大神

回复:
user: user-1
content: 抽空定了段代码，供参考，有能力自已再优化一下  #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 100  typedef struct student { 	char name[20]; 	int age; 	int math; 	int physics; 	int chermistry; 	int total; 	float average; }STU;  //输入 void inputSTU(STU *arr, int n) { 	int i = 0; 	for ( i = 0; i < n; i++ ) 	{ 		printf("输入第%d个学生的姓名 年龄 数学 物理 化学成绩：\n", i + 1); 		scanf("%s%d%d%d%d", arr[i].name, &arr[i].age, &arr[i].math, &arr[i].physics, &arr[i].chermistry); 		arr[i].total = arr[i].math + arr[i].physics + arr[i].chermistry; 		arr[i].average = arr[i].total * 1.0 / 3; 		getchar(); 	} }   //最高分 void maxSTU(STU *arr, int n, const char *str) { 	int i = 0, j = 0, max = 0; 	 	if (strcmp(str, "总分") == 0) 	{ 		for (i = 0; i < n; i++) 		{ 			if ( max < arr[i].total ) 			{ 				max = arr[i].total; 				j = i; 			} 		} 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[j].name, arr[j].age, arr[j].math, 			   arr[j].physics, arr[j].chermistry, arr[j].total, arr[j].average);  	} 	else if ( strcmp(str, "数学") == 0 ) 	{ 		for ( i = 0; i < n; i++ ) 		{ 			if ( max < arr[i].math ) 			{ 				max = arr[i].math; 				j = i; 			}				 		} 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[j].name, arr[j].age, arr[j].math, 			   arr[j].physics, arr[j].chermistry, arr[j].total, arr[j].average); 	} 	else if ( strcmp(str, "物理") == 0 ) 	{ 		for ( i = 0; i < n; i++ ) 		{ 			if ( max < arr[i].physics ) 			{ 				max = arr[i].physics; 				j = i; 			} 		} 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[j].name, arr[j].age, arr[j].math, 			   arr[j].physics, arr[j].chermistry, arr[j].total, arr[j].average); 		 	} 	else if ( strcmp(str, "化学") == 0 ) 	{ 		for ( i = 0; i < n; i++ ) 		{ 			if ( max < arr[i].chermistry ) 			{ 				max = arr[i].chermistry; 				j = i; 			} 		} 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[j].name, arr[j].age, arr[j].math, 			   arr[j].physics, arr[j].chermistry, arr[j].total, arr[j].average);		 	} }  //挂科 void failSTU(STU *arr, int n) { 	int i = 0, count = 0; 	char course[10]; 	printf("\n输入要查询的挂科科目:\n\n"); 	scanf("%s", course);  	if (strcmp(course, "数学") == 0) 	{ 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		for (i = 0; i < n; i++) 		{ 			if (arr[i].math < 60) 			{ 				printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[i].name, arr[i].age, arr[i].math, 					   arr[i].physics, arr[i].chermistry, arr[i].total, arr[i].average); 				count++; 			} 		} 		printf("%s挂科的人数：%d", course, count); 	} 	else if ( strcmp(course, "物理") == 0 ) 	{ 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		for ( i = 0; i < n; i++ ) 		{ 			if ( arr[i].physics < 60 ) 			{ 				printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[i].name, arr[i].age, arr[i].math, 					   arr[i].physics, arr[i].chermistry, arr[i].total, arr[i].average); 				count++; 			} 		} 		printf("%s挂科的人数：%d", course, count); 	} 	else if ( strcmp(course, "数学") == 0 ) 	{ 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		for ( i = 0; i < n; i++ ) 		{ 			if ( arr[i].chermistry < 60 ) 			{ 				printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[i].name, arr[i].age, arr[i].math, 					   arr[i].physics, arr[i].chermistry, arr[i].total, arr[i].average); 				count++; 			} 		} 		printf("%s挂科的人数：%d", course, count); 	} }  //平均分降序 void sortSTU(STU *arr, int n) { 	STU temp; 	int i = 0, j = 0; 	for (i = 0; i < n - 1; i++) 	{ 		for (j = 0; j < n - 1 - i; j++) 		{ 			if (arr[j].average < arr[j+1].average) 			{ 				temp = arr[j]; 				arr[j] = arr[j + 1]; 				arr[j + 1] = temp; 			} 		} 	}  	printf("\n\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 	for ( i = 0; i < n; i++ ) 	{ 		printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[i].name, arr[i].age, arr[i].math, 			   arr[i].physics, arr[i].chermistry, arr[i].total, arr[i].average); 	} }  //按分数段查询 void scoreSTU(STU *arr, int n) { 	int i = 0, score = 0; 	printf("\n\n输入要查询的分数段：\n\n"); 	scanf("%d", &score);  	if (score < 60) 	{ 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		for (i = 0; i < n; i++) 		{ 			if (arr[i].average < 60) 			{ 				printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[i].name, arr[i].age, arr[i].math, 					   arr[i].physics, arr[i].chermistry, arr[i].total, arr[i].average); 			} 		} 	} 	else if ( score >= 60 && score < 70 ) 	{ 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		for ( i = 0; i < n; i++ ) 		{ 			if ( arr[i].average >= 60 && arr[i].average < 70 ) 			{ 				printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[i].name, arr[i].age, arr[i].math, 					   arr[i].physics, arr[i].chermistry, arr[i].total, arr[i].average); 			} 		} 	} 	else if ( score >= 70 && score < 80 ) 	{ 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		for ( i = 0; i < n; i++ ) 		{ 			if ( arr[i].average >= 70 && arr[i].average < 80 ) 			{ 				printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[i].name, arr[i].age, arr[i].math, 					   arr[i].physics, arr[i].chermistry, arr[i].total, arr[i].average); 			} 		} 	} 	else if ( score >= 80 && score < 90 ) 	{ 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		for ( i = 0; i < n; i++ ) 		{ 			if ( arr[i].average >= 80 && arr[i].average < 90 ) 			{ 				printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[i].name, arr[i].age, arr[i].math, 					   arr[i].physics, arr[i].chermistry, arr[i].total, arr[i].average); 			} 		} 	} 	else if ( score >= 90 && score < 100 ) 	{ 		printf("\n姓名\t年龄\t数学\t物理\t化学\t总分\t平均分\n"); 		for ( i = 0; i < n; i++ ) 		{ 			if ( arr[i].average >= 90 && arr[i].average < 100 ) 			{ 				printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n", arr[i].name, arr[i].age, arr[i].math, 					   arr[i].physics, arr[i].chermistry, arr[i].total, arr[i].average); 			} 		} 	} 	else 	{ 		printf("\n超出范围!\n"); 		return; 	} }  int main(void) { 	STU myArray[N]; 	int num = 0; 	char str[10];  	printf("输入学生人数：\n"); 	scanf("%d", &num);  	//输入 	inputSTU(myArray, num); 	 	//总分最高分 	maxSTU(myArray, num, "总分");  	//单科最高分 	printf("\n输入要查询最高分的单科：\n\n"); 	scanf("%s", str); 	maxSTU(myArray, num, str);  	//单科挂科 	failSTU(myArray, num);  	//平均分降序输出 	sortSTU(myArray, num);  	//按分数段查询 	scoreSTU(myArray, num); 	  	getchar();     return 0; }

user: user-0
content: 引用 1 楼 user-1的回复:使用结构体数组？使用链表？ 结构体

user: user-1
content: 使用结构体数组？使用链表？