Anonymous user
Averages/Arithmetic mean: Difference between revisions
added c#
m (oct...) |
(added c#) |
||
Line 150:
return std::accumulate(numbers.begin(), numbers.end(), 0.0) / numbers.size();
}
=={{header|C sharp|C#}}==
<lang csharp>static float avg(ICollection<int> i)
{
return i.Sum() / (float)i.Count;
}
static void Main(string[] args)
{
int[] numbers = new int[] {1, 2, 3, 4, 5, 6, 7, 8};
Console.WriteLine(avg(numbers));
}</lang>
C# already has a builtin Avarage function.
<lang csharp>static void Main(string[] args)
{
int[] numbers = new int[] {1, 2, 3, 4, 5, 6, 7, 8};
Console.WriteLine(numbers.Average());
}</lang>
=={{header|Common Lisp}}==
|