Language: C#
I have an array of numbers that the user entered, and I want to find the arithmetic mean of the array.
I looked up a couple of similiar cases, but couldn't really find anything I was looking for... Anyway, here is the code:
Console.WriteLine("
How many numbers do you want to average?
");
int nNumtoAvg = Convert.ToInt32(Console.ReadLine());
int[] nListToAverage = new int[nNumtoAvg];
for (int i = 0; i < nNumtoAvg; i++)
{
Console.WriteLine("Enter whole number #" + (i + 1) + ": ");
string sVal = Console.ReadLine();
int nValue = Convert.ToInt32(sVal);
nListToAverage[i] = nValue;
}
Now, what would I do to add all the numbers in the array together, and then divide that by the array.Length? Thanks in advance :D
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…