/*编写一个程序,
输入n个学生的学号,姓名,3门课程的成绩,
求出总分最高的学生并输出该学生的所有信息*/
#include <stdio.h>
#define SIZE 80
typedef struct student{
char studentID[SIZE];
char studentName[SIZE];
float scoreComputer;
float scoreEnglish;
float scoreMath;
}stu;
main()
{
stu astu[SIZE];
int n,i;
float sum;
float max=0;
int flag =0;
printf("please enter the total number:");
scanf("%d",&n);
printf("please enter the information of everybody:\n");
for (i=0;i<n;i++)
{
printf("ID:");
scanf("%s",astu[i].studentID);
printf("NAME:");
scanf("%s",astu[i].studentName);
printf("scoreComputer:");
scanf("%f",&astu[i].scoreComputer);
printf("scoreEnglish:");
scanf("%f",&astu[i].scoreEnglish);
printf("scoreMath:");
scanf("%f",&astu[i].scoreMath);
}
for (i=0;i<n;i++)
{
sum=astu[i].scoreComputer+astu[i].scoreEnglish+astu[i].scoreMath;
if(sum>max){
max =sum;
flag =i;
}
}
printf("-------------------------------------------\n");
printf("ID\tNAME\tCOMPUTER\tENGLISH\tMATH\n");
for(i =0;i<n;i++){
printf("%s\t%s\t%f\t%f\t%f\n",astu[i].studentID,astu[i].studentName,\
astu[i].scoreComputer,astu[i].scoreEnglish,astu[i].scoreMath);
}
printf("-------------------------------------------\n");
printf("ID:%s,Name:%s,Computer:%f,English:%f,Math:%f\n",\
astu[flag].studentID,astu[flag].studentName,\
astu[flag].scoreComputer,astu[flag].scoreEnglish,astu[flag].scoreMath);
}
这里有一个运用结构体写的,输入的数据没有经过处理,希望对你有所帮助。有问题可以加我QQ:153612021.希望我们共同进步。