Friday, 1 December 2017

C# Program to Compute Average for the Set of Values


Code:

using System;
class program
{
    public static void Main()
    {
        int m, i, sum = 0, avg = 0;
        Console.WriteLine("Enter the Number of Terms in the Array ");
        m = int.Parse(Console.ReadLine());
        int[] a = new int[m];
        Console.WriteLine("Enter the Array Elements ");
        for (i = 0; i < m; i++)
        {
            a[i] = int.Parse(Console.ReadLine());
        }
        for (i = 0; i < m; i++)
        {
            sum += a[i];
        }
        avg = sum / m;
        Console.WriteLine("Average is {0}", avg);
        Console.ReadLine();
    }
}


Output:

Enter the Number of Terms in the Array : 4
Enter the Elements
1
2
3
4
Average is 2


More C# Programs:



















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...