adspace
In a gymnastic competition, scoring is based on the average
of all scores given by the judges excluding the maximum and
minimum scores.
Let the user input the number of judges, after that, input
the scores from the judges.
Output the average score.
Note: In case, more than two judges give the same score and
it happens that score is the maximum or minimum then just
eliminate two scores.
For example, if the number of judges is 5 and all of them
give 10 points each. Then the maximum and minimum score is
10. So the computation would be 10+10+10, this time.
The output should be 10 because 30/3 is 10.
Answer Posted / Sohan Singh
Here's a C code snippet that implements this:n```n#include <stdio.h>n#define NMAX 100nint main(void) {n int n, i, j, temp = 0;n double scores[NMAX], sum = 0;n scanf("%d", &n);n for (i = 0; i < n; i++) {n scanf("%lf", &scores[i]);n }n // Sort the arraynsort(scores, n);n // Calculate sum of scores without maximum and minimumn for (i = 1; i < n - 1; i++) {n if (scores[i] > temp) {n temp = scores[i];n }n }n for (i = 0; i < n; i++) {n if (scores[i] != temp && scores[i] < temp) {n sum += scores[i];n }n }n // Output the average scorensum /= (n - 2);n printf("The average score is: %.2f
", sum);n return 0;n}nvoid sort(double arr[], int n) {n for (int i = 0; i < n - 1; i++) {n for (int j = 0; j < n - i - 1; j++) {n if (arr[j] > arr[j + 1]) {n double temp = arr[j];n arr[j] = arr[j + 1];n arr[j + 1] = temp;n }n }n }n``` This code sorts the scores, eliminates the maximum and minimum, and calculates the average.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers