link如何完成如下算法?

有一个数组,共有n个元素,要求输出所有比它到它前面平均数小的元素。

和bdmh的略有不同。看你怎么理解“它到它前面平均数”是否包含它。

如果包含,最后的4就不算。

1
2
0
请按任意键继续. . . 
        List<int> list = new List<int>(new int[] { 2, 4, 6, 1, 2, 8, 9, 0, 4 });
        int[] arr = list.Where((mm, index) => mm<list.Average(v=>index-1)).ToArray();

上面是c#的linq

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> list = new List<int>() { 2, 4, 6, 1, 2, 8, 9, 0, 4 };
            int[] arr = list.Where((x, i) => list.Take(i + 1).Average() > x).ToArray();
            foreach (int item in arr)
            {
                Console.WriteLine(item);
            }
        }
    }
}