Hello. Im new on this forum so please go easy. I have an exam coming up soon and Im having trouble understanding the solution to the last answer in the exam. Ive listed both the question and answer below.
Question:
How would you declare a list of floating numbers in C? Write a function that calculates the mean value of these numbers, and another function that sorts the list into the list of numbers lower than this mean value and the list of numbers higher than this mean value.
Answer:
Code:
float list[];
float meanValue(float myList[10])
{
float sum=0;
int counter=0;
while (counter <10)
{
sum += myList[counter];
counter++;
}
return sum/counter;
}
void sortMiddle(float myList[10], float middle, float inferior[10], float superior[10])
{
int counter1=0, counter 2=0, counter 3=0;
while (counter1<10)
{
if (myList[counter1] <= middle)
{
inferior[counter2]=myList[counter1];
counter2++;
}
else
{
superior[counter3]=myList[counter1];
counter3++;
}
counter1++;
}
}
This is pretty advanced for me as I have been learning at a lower level. I would really appreciate it if someone could help me understand the example answer code.
Rick