Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Language: C# I\'m having trouble with a practice program. >> Program named Numbe

ID: 3674113 • Letter: L

Question

Language: C#

I'm having trouble with a practice program. >> Program named NumberAverage that includes a method that accepts any number of numeric parameters, displays them, and displays their average. Demonstrate that the method works correctly when passed one, two, or three numbers, or an array of numbers. The user does NOT input numbers. The numbers are called from the method and the output is as follows:

7 -- Average is 7

12 15 -- Average is 13.5

22.3 44.5 88.1 -- Average is 51.

3 4 5 6 7 8 -- Average is 5.5

Explanation / Answer

/*

* C# Program to Find the Average Values of all in array

*/

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

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("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 pg = new program();

        pg.sumAverageElements(a, len);

    }

}

Here is the output: