Q:

get "running average" of a list

Say I've got a list:
List<int> numbers = new List<int>();

and I'm trying to get the "running averages" of it. (Sorry, I don't really know how to call it).
For instance:
The first item in this list is 5, the average of 5 is 5, so the first average is 5. 
The second item in this list is 7, the average of 5 and 7 is 6, so the second average is 6.
The third item in this list is 10, the average of 5, 7 and 10 is 7.3, so the third average is 7.3
And so on.
Those first average, second average etc are the averages I'm trying to get. How would I go about doing this? I've been searching the internet but honestly I'm not quite sure what I should be looking for. :(

A:

try this:
 string st = Console.ReadLine();
 string[] strs = st.Split(' ');
 List<int> numbers = new List<int>();
 List<double> averages = new List<double>();
 for (int i = 0; i < strs.Length; i++)
 {
     numbers.Add(int.Parse(strs[i]));
     averages.Add(numbers.Average());
 }

this will read the numbers from the standard input, the numbers are separated by space in input.

A:

You can try something like this:
var averages = Enumerable.Range(1, numbers.Count)
               .Select(x => numbers.Take(x).Average())
               .ToList();

This will generate a sequence from 1 to numbers.Count. Then using Take it will get X element at each time (you can think X as an index, only difference is it starts from 1 and increases one by one up to the numbers.Count) starting from the first element then get their average.Put them into a list.

