C语言高手进!
定义一个结构体数组,存放 10个学生的学号,姓名,三门课的成绩,输出单门课成绩最高的学生的学号、姓名、以及该门课程的成绩,输出三门 课程的平均分数最高的学生的学号、姓名及其平均分,再将 10个学生按照平均分数从高到低进行排序,输出结果。
追问:问一下,又没调试过呢?
定义一个结构体数组,存放 10个学生的学号,姓名,三门课的成绩,输出单门课成绩最高的学生的学号、姓名、以及该门课程的成绩,输出三门 课程的平均分数最高的学生的学号、姓名及其平均分,再将 10个学生按照平均分数从高到低进行排序,输出结果。
追问:问一下,又没调试过呢?
答案:如下,望采纳:#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <memory>
#include <cstring>
using namespace std;typedef struct Student
{
char num[20];
char name[20];
double score[3];
double aver;
}STU;
STU s[10];
int i,j;int main()
{
double max1=0,max2=0,max3=0,max4=0;
int pos1=0,pos2=0,pos3=0,pos4=0;
printf("Input the data(Number,Name & 3 Scores) of 10 students:\n");
for(i=0;i<10;i++)
{
scanf("%s %s %lf %lf %lf",s[i].num,s[i].name,&(s[i].score[0]),&(s[i].score[1]),&(s[i].score[2]));
s[i].aver=(s[i].score[0]+s[i].score[1]+s[i].score[2])/3.0;
}
for(j=0;j<10;j++)
{
if(s[j].score[0]>max1)
{
max1=s[j].score[0];
pos1=j;
}
if(s[j].score[1]>max2)
{
max2=s[j].score[1];
pos2=j;
}
if(s[j].score[2]>max3)
{
max3=s[j].score[2];
pos3=j;
}
if(s[j].aver>max4)
{
max4=s[j].aver;
pos4=j;
}
}
printf("The highest of score 1 is:\n");
printf("%s %s %lf\n",s[pos1].num,s[pos1].name,s[pos1].score[0]);
printf("The highest of score 2 is:\n");
printf("%s %s %lf\n",s[pos2].num,s[pos2].name,s[pos2].score[1]);
printf("The highest of score 3 is:\n");
printf("%s %s %lf\n",s[pos3].num,s[pos3].name,s[pos3].score[2]);
printf("The highest average is:\n");
printf("%s %s %lf\n",s[pos4].num,s[pos4].name,s[pos4].aver);
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(s[j].aver>s[i].aver)
swap(s[j],s[i]);
}
}
printf("The list is:\n");
for(int j=0;j<10;j++)
printf("%s %s %lf\n",s[j].num,s[j].name,s[j].aver);
system("pause");
return 0;
}
简单易懂,有问题在线修改!
==============================================
#include<stdio.h>
#define HUMMAX 10 //一个班级人数最大值
#define CLASSMAX 3 //课程数struct Student
{
char Num[10]; //学号
char Name[10]; //姓名
float Score[CLASSMAX]; //三门成细
}s[HUMMAX];
void Input_StudentInfo(); //输入学生信息
void Output_ClassGood(); //单门课成绩最高信息
void Output_AvgGood(); //平均成绩最高信息
void Output_AvgOrder(); //平均分排序信息void main()
{
Input_StudentInfo();
Output_ClassGood();
Output_AvgGood();
Output_AvgOrder();
}void Input_StudentInfo()
{
int i=0,j=0;
printf("Input Student Info:\n");
for (i=0; i<HUMMAX; i++)
{
printf("NO.%d\n",i);
printf("Num:"); scanf("%s",s[i].Num);
printf("Name:"); scanf("%s",s[i].Name);
for (j=0; j<CLASSMAX; j++)
{
printf("Score%d:",j);
scanf("%f",&s[i].Score[j]);
}
}
}void Output_ClassGood()
{
float MaxScore=0;
int i=0,j=0,k=0;
for (i=0; i<HUMMAX; i++)
for (j=0; j<CLASSMAX; j++)
if (s[i].Score[j]>MaxScore)
{
MaxScore=s[i].Score[j];
k=i;
}
printf("\n\nA Class Score Good:\n");
printf("Num:%s\nName:%s\n",s[k].Num,s[k].Name);
printf("Score1~3:%f %f %f\n",s[k].Score[0],s[k].Score[1],s[k].Score[2]);
}void Output_AvgGood()
{
float Avg=0,Sum=0;
int i=0,j=0,k=0;
for (i=0; i<HUMMAX; i++)
{
for (j=0; j<HUMMAX; j++)
Sum+=s[i].Score[j];
if (Sum>Avg)
{
Avg=Sum;
k=i;
}
}
printf("\n\nAvg Class Score Good:\n");
printf("Num:%s\nName:%s\n",s[k].Num,s[k].Name);
printf("Score1~3:%f %f %f\n",s[k].Score[0],s[k].Score[1],s[k].Score[2]);
printf("Average Score:",s[k].Score[0]+s[k].Score[1]+s[k].Score[2]);
}void Output_AvgOrder()
{
float Avg,TAvg;
Student ts;
int i=0,j=0,k=0;
for (i=0; i<HUMMAX-1; i++)
{
Avg=0;
for (k=0; k<CLASSMAX; k++)
Avg+=s[i].Score[k];
for (j=i+1; j<HUMMAX; j++)
{
TAvg=0;
for (k=0; k<CLASSMAX; k++)
TAvg+=s[j].Score[k];
if (TAvg>Avg)
&nb