Calculate average for a list of integer values with params int[] values
class TestParams
{
private static void Average(string title, params int[] values)
{
int sum = 0;
for (int i = 0; i < values.Length; i++)
{
sum += values[i];
System.Console.Write(values[i] + ", ");
}
System.Console.WriteLine((float)sum/values.Length);
}
static void Main()
{
Average ("List One", 5, 10, 15);
Average ("List Two", 5, 10, 15, 20, 25, 30);
}
}
Related examples in the same category