#include<stdio.h>
typedef struct grade
{
float score;
float absolutevalue;
int num;
}Pingwei;
int main()
{
int i,j,k;
float temp,sum;
Pingwei a[10].score;
printf(“请输入10个评委的分数(0~100):\n”);
for(i=0;i<10;i++)
{
printf(“请输入%d号评委的分数(0~100):\n”,i+1);
scanf(“%f”,&a[i].score);
a[i].num=i+1;
a[i].absolutevalue=0;
}
for(i=0;i<9;i++)
for(j=i+1;j<10;j++)
{
if(a[i].score>a[j].score)
{
temp=a[i].score;
k=a[i].num;
a[i].score=a[j].score;
a[i].num=a[j].num;
a[j].score=temp;
a[j].num=k;
}
}
for(i=0;i<10;i++)printf(“%f “,a[i].score );
sum=0;
for(i=1;i<9;i++)
{
sum+=a[i].score;
}
sum/=8;
printf(“请输出剩下8个的平均分: “);
printf(“%f\n”,sum);
for(i=1;i<9;i++)
{
a[i].absolutevalue=a[i].score-sum;
if(a[i].absolutevalue<0)a[i].absolutevalue=-a[i].absolutevalue;
}
for(i=1;i<8;i++)
for(j=i+1;j<9;j++)
{
if(a[i].absolutevalue>a[j].absolutevalue)
{
temp=a[i].absolutevalue;
k=a[i].num;
a[i].absolutevalue=a[j].absolutevalue;
a[i].num=a[j].num;
a[j].absolutevalue=temp;
a[j].num=k;
}
}
for(i=1;i<9;i++)printf(“%3d”,a[i].num);
printf(“\n”);
for(i=1;i<9;i++)printf(“%f “,a[i].absolutevalue);
printf(“\n”);
printf(“与平均分最接近的评委: %d号评委”,a[1].num);
for(i=2;i<9;i++)
{
if(a[i].absolutevalue ==a[1].absolutevalue)printf(” %d号评委 “,a[i].num);
}
printf(“\n与平均分相差最大分数的评委: %d号评委”,a[8].num);
for(i=7;i>1;i–)
if(a[i].absolutevalue ==a[8].absolutevalue)printf(” %d号评委 “,a[i].num);
printf(“\n”);
return 0;
}
/*
85
68
79
99
65
78
93
85
62
83
*/
>> 本文固定链接: http://www.vcgood.com/archives/1830
Pingwei a[10].score;?????
Pingwei a[10];