You possibly meant
using System;
public class Test
{
public static void Main()
{
const int NUMBERS = 1000;
Random myRandom = new Random();
int [] a = new int[NUMBERS];
int i = 0;
int max = int.MinValue, min = int.MaxValue, sum = 0;
while (i < NUMBERS)
{
a[i] = myRandom.Next(1, 501);
if (max < a[i]) max = a[i];
if (min > a[i]) min = a[i];
sum += a[i];
++i;
}
double avg = (double)sum / NUMBERS;
Console.WriteLine("The minimum number is: {0}", min );
Console.WriteLine("The maximum number is: {0}", max);
Console.WriteLine("The average of these numbers is: {0}", avg);
}
}
Please note you actually don't need to store the extracted numbers in the array in order to compute minimum, maximum and average.
[Update]
Quote:
Thanks for the advice, and the solution, really helpful. I was wondering how I would go about putting the commands for finding the minimum, maximum and average of the numbers in different methods?
Then the essential modification is you need to pass the array to the relevant method, e.g.
public static int find_min(int[] a)
{
int min = int.MaxValue;
for (int n = 0; n < a.Length; ++n)
{
if (min > a[n]) min = a[n];
}
return min;
}
[/Update]