4. 编写一个程序,读入9个裁判所打的分数,去掉一个最高分,去掉一个最低分,求剩余7个分数的平均值(要求用数组实现)。

#include <stdio.h>

void main()
{
	float score[10], sumScore, minScore, maxScore;
	int i, j;
	for (i = 0; i < 9; i ++)
	{
		printf("please input %d score\n", i + 1);
		scanf("%f", &score[i]);
	}
	sumScore = minScore = maxScore = score[0];
	for (j = 1; j < 9; j ++)
	{
		if (score[j] > maxScore)
		{
			maxScore = score[j];
		}
		else if (score[j] < minScore)
		{
			minScore = score[j];
		}
		sumScore += score[j];
	}
	sumScore -= maxScore;
	sumScore -= minScore;

	printf("the average is %f\n", sumScore/7);
}

  

posted @ 2011-10-28 14:10  末世  阅读(371)  评论(0编辑  收藏  举报