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.



In a gymnastic competition, scoring is based on the average of all scores given by the judges excl..

Answer / 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

More C Code Interview Questions

Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange

1 Answers  


write a program to find out roots of quadratic equation "x=-b+-(b^2-4ac0^-1/2/2a"

2 Answers  


void main() { int *mptr, *cptr; mptr = (int*)malloc(sizeof(int)); printf(“%d”,*mptr); int *cptr = (int*)calloc(sizeof(int),1); printf(“%d”,*cptr); }

1 Answers  


String copy logic in one line.

11 Answers   Microsoft, NetApp,


C program to print magic square of order n where n > 3 and n is odd

2 Answers   Accenture,


what is the code of the output of print the 10 fibonacci number series

2 Answers  


char inputString[100] = {0}; To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString, sizeof(inputString), fp)

1 Answers  


#ifdef something int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }

1 Answers  


main() { main(); }

1 Answers  


int aaa() {printf(“Hi”);} int bbb(){printf(“hello”);} iny ccc(){printf(“bye”);} main() { int ( * ptr[3]) (); ptr[0] = aaa; ptr[1] = bbb; ptr[2] =ccc; ptr[2](); }

1 Answers  


How we will connect multiple client ? (without using fork,thread)

3 Answers   TelDNA,


int i,j; for(i=0;i<=10;i++) { j+=5; assert(i<5); }

3 Answers   Cisco, HCL,


Categories