I have already develop a program that to receive the users' input of a positive integer numbers and to output the average for all the inputted numbers.
Now I am asked to modify the program so that it can display the largest numbers received from the users' input. However, I am quiet confused with it and don't know what to do.
#include <stdio.h>
main() {
int input;
int numbers[12];
int index = 0;
int i;
int sum;
float average=0.0;
do{
printf("Please input a positive integer, 0 to leave.\n");
scanf("%d", &input);
average = (average*index + input)/(index+1);
index++;
printf("The average is: %2.2f\n", average);
}
while(input!=0);
printf("Now quit!\n");
}
Your program shows "average" after each input. Why?
What are those variables on lines 6, 8 and 9? They are not used anywhere.
Lets say that I type two numbers: 1 and 0. The loop quits after the 0 and the average is 0.5, (because 1/2 = 0.5). Is that right?
Lets pretend that you have handled some input values and know how large the largest was.
Now you get a new value.
How could you know whether the new value is larger than the largest so far?
How you would be sure that the largest value so far is up to date after this input?
How large should the "largest value so far" be before the first input?