Hi friends, I am going to write a simple program to calculate the average for the set of values. It is easy to calculate the average of numbers, to find the average of numbers just add up all the numbers, then divide by how many numbers there are. In other words, it is the sum divided by the count.

C# Program to calculate the average for the set of values:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text;
using System.Runtime.Serialization.Json;
namespace CheckPrimeUsingRecursion
{
 class Program
 {
 
 static void Main(string[] args)
 {

int iNumberofItem, iCount, iSum = 0, iAverage = 0;
 Console.WriteLine("Enter the Number of Items in the Array ");
 iNumberofItem = int.Parse(Console.ReadLine());
 int[] arrItem = new int[iNumberofItem];
 Console.WriteLine("Enter the Array Elements ");
 for (iCount = 0; iCount < iNumberofItem; iCount++)
 {
 arrItem[iCount] = int.Parse(Console.ReadLine());
 }
 for (iCount = 0; iCount < iNumberofItem; iCount++)
 {
 iSum += arrItem[iCount];
 }
 iAverage = iSum / iNumberofItem;
 Console.WriteLine("Average is {0}", iAverage);
 Console.ReadLine();
 
 }
 
 }
}

Output:

Enter the Number of Items in the Array
4
Enter the Array Elements
6
4
6
7
Average is 5

View More:

Conclusion:

I hope you would love this post. I would appreciate your suggestions and feedback. Please don’t hesitate to comment for any technical help.

Leave a Comment