Q:

Write C# Program to Find the Average Values of all the Array Elements

0

Write C# Program to Find the Average Values of all the Array Elements

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System;
class Program
{
    public void sumAverageElements(int[] arr, int size)
    {
 
        int sum = 0;
        int average = 0;
        for (int i = 0; i < size; i++)
        {
            sum += arr[i];
        }
        average = sum / size;
        Console.WriteLine("Sum Of Array is : " + sum);
        Console.WriteLine("Average Of Array is : " + average);
        Console.ReadLine();
    }
    public static void Main(string[] args)
    {
        int size;
        Console.WriteLine("Enter the Size :");
        size = Convert.ToInt32(Console.ReadLine());
        int[] a = new int[size];
        Console.WriteLine("Enter the Elements of the Array : ");
        for (int i = 0; i < size; i++)
        {
            a[i] = Convert.ToInt32(Console.ReadLine());
        }
        int len = a.Length;
        Program p = new Program();
        p.sumAverageElements(a, len);
    }
 
}

Result:

Enter the Size :

5

Enter the Elements of the Array : 

10

20

30

40

50

Sum Of Array is : 150

Average Of Array is : 30

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C# program to find reverse of an array... >>
<< Write C# program to merge two sorted array...