Beginner programming question
I am new to arrays and I need help! I am trying to write code that will allow me to declare an array of five numbers and then add the numbers together and find the average of the five numbers. I am totally lost on this so any help would be greatly appreciated!!
Blocked AccountPosted Dec 17, 2007, 2:17 AM
I am posting the code for you. Here i have declared n size array and print the average of the array values.
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter The size of the array");
int size = int.Parse(Console.ReadLine());
int[] myArray = new int[size];
int sumArray = 0;
Console.WriteLine("Enter The values in the array");
for (int i = 0; i < size; i++)
{
myArray[i] = int.Parse(Console.ReadLine());
}
for (int j = 0; j < size; j++)
{
sumArray = sumArray + myArray[j];
}
float average = sumArray / size;
Console.WriteLine("Average of the array values is="+ average);
}
}
Happy Coding !!
chadPosted Dec 17, 2007, 12:59 AM
Posted Dec 17, 2007, 12:35 AM
http://en.csharp-online.net/All_about_Arrays_in_CSharp%E2%80%94
Arrays?csharpon_cswiki_cs__session=d776cc26e47150b37d4125c7e2344bb9
Above website teaches about arrays. See whether this website is helpful.
http://www.java2s.com/Code/CSharp/Collections-Data-Structure/Array.htm
3rd example program in the above website is answering your question.