Basic C Language Algorithm 08-remove the highest score, remove the lowest score, and calculate the average value.
//
/*
========================================================== ======================================
Question: This method is usually used to calculate a contestant's score during the competition. Remove a highest score and
Lowest score, calculate the average score! Program this calculation method.
========================================================== ======================================
*/
# Include <stdio. h>
Main ()
{
Float a [10], max, min, sum = 0.0, aver;
Int I;
Printf ("input score: \ n ");
For (I = 0; I <10; I ++)
{
Printf ("score % 2d:", I + 1 );
Scanf ("% f", & a [I]);
If (a [I] <0) | (a [I]> 10 ))
{
Printf ("Incorrect Score Input !, Make sure that the score is 0-10! \ N __________________________ \ n ");
I =-1;
}
}
Max = a [0]; min = a [0];
For (I = 0; I <10; I ++)
{
If (max <a [I])
Max = a [I];
If (min> a [I])
Min = a [I];
Sum = sum + a [I];
}
Aver = (sum-max-min)/8;
Printf ("Remove the highest score: %. 1f \ n", max );
Printf ("remove a partition: %. 1f \ n", min );
Printf ("average score: %. 2f \ n", aver );
}
/*
========================================================== ======================================
Rating: define the number of judges (10), input the score (Series a []), calculate the maximum and minimum values, and sum
Sum, calculates sum-highest score-lowest score, and calculates the average value.
========================================================== ======================================
*/
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.