#include <stdio.h>
#include <conio.h>
#define MAX 3
#define S_MAX 3
struct singer
{
int num;
char name[8];
double score[S_MAX];
double aver;
}sin[MAX];
struct singer *sort(struct singer s[])
{
int j,k;
struct singer e;
for(j=0;j<MAX-1;j++)
{
for(k=j;k<MAX;k++)
if(s[j].aver<s[k].aver)
{
e=s[j];
s[j]=s[k];
s[k]=e;
}
}
return s;
}
double get_aver(double s[])
{
int j;
double sum;
double ma,mi;
ma=mi=s[0];
for(j=0;j<S_MAX;j++)
{
ma=ma>s[j]?ma:s[j];
mi=mi<s[j]?mi:s[j];
}
for(j=0;j<S_MAX;j++)
sum+=s[j];
sum-=ma+mi;
return (double)sum/(S_MAX-2.0);
}
main()
{
double sum=0,e;
int j,k;
for(k=0;k<MAX;k++)
{
printf("please input num:");
scanf("%d",&sin[k].num);
printf("Please input name:");
scanf("%s",sin[k].name);
printf("please input score:\n");
for(j=0;j<S_MAX;j++)
{
printf("score%2d:",j+1);
scanf("%lf",&e);
sin[k].score[j]=e;
}
sin[k].aver=get_aver(sin[k].score);
}
sort(sin);
for(k=0;k<MAX;k++)
{
printf("%lf,%d,%s\n",sin[k].aver,sin[k].num,sin[k].name);
}
printf("Input ESC out!");
while(getch()!=27);
}
先做个简单的
你没做什么美化和其他的便利调试