Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your program should read oating point values from the input, up to (and includin

ID: 3838466 • Letter: Y

Question

Your program should read oating point values from the input, up to (and including) 100 values. Youshould then print the median of the values read by your program.Your program should stop reading input values if
1. It reads -999 from the input or2. It reads 100 values from the input.If the number of values entered by the user is equal to 100, you should stop when reading the 100th
value from the input and calculate the median.Your program must not print any instructions to the screen. It should only read oating point valuesuntil a value equal to -999 is presented by the user or until 100 values are read from the input.

This must be done in c not c++ or C#

Explanation / Answer

#include <stdio.h>

int main()
{
double d[100];
int i;
double median;
for(i=0;i<100;i++){
printf("Enter the floating number (-999 to quit): ");
scanf("%lf", &d[i]);
if(d[i] == -999){
break;
}
}
if(i % 2 == 0){
median = (d[i/2] + d[(i-1)/2])/2;
}
else{
median = d[i/2];
}
printf("Median is %lf ", median);
return 0;
}

Output:

sh-4.2$ gcc -o main *.c                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter the floating number (-999 to quit): 3                                                                                                                                                                                                                            

Enter the floating number (-999 to quit): 4                                                                                                                                                                                                                            

Enter the floating number (-999 to quit): 5                                                                                                                                                                                                                            

Enter the floating number (-999 to quit): 5                                                                                                                                                                                                                            

Enter the floating number (-999 to quit): 6.7                                                                                                                                                                                                                          

Enter the floating number (-999 to quit): 7.8                                                                                                                                                                                                                          

Enter the floating number (-999 to quit): 8.9                                                                                                                                                                                                                          

Enter the floating number (-999 to quit): -999                                                                                                                                                                                                                         

Median is 5.000000