Average an Array items in C#

In this article I will explain that how to Average in Array.
  • 4802

The Average method is equivalent to adding up the total of all of the numbers, and then dividing that total by the number of elements. Simple definition, average of n numbers is the total cumulative of data divided by n, one of the statistics besides maximum and minimum value.

namespace demo_array

{

    class Program

    {

      

        static void Main(string[] args)

        {

            double  avg = 0;

            double[] nums = new double[5];             

            nums[0] = 10;

            nums[1] = 12;

            nums[2] = 14;

            nums[3] = 20;

            nums[4] = 50;

            for (int  i = 0; i < 5; i++) 

              avg = avg + nums[i];

 

            avg = avg / 5;

 

            Console.WriteLine("Average: " + avg);

 

            Console.ReadKey();

        }

 

    }

}

Output

Avg_array.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.