HomeCSharpC# Program to Find the Mean

C# Program to Find the Mean

In statistics, the mean is the average of a set of numbers. In this task, we will write a C# program to find the mean of a set of numbers.

Problem Statement

Write a C# program to find the mean of a set of numbers. The program should take input from the user in the form of a set of numbers. The program should display the mean of the numbers as output.

C# Program to Find the Mean

using System;

class Program
    static void Main(string[] args)
        Console.WriteLine("Enter the numbers separated by spaces: ");
        string input = Console.ReadLine();
        string[] numbers = input.Split(' ');

        double sum = 0;
        foreach (string number in numbers)
            sum += double.Parse(number);

        double mean = sum / numbers.Length;
        Console.WriteLine("Mean: {0}", mean);

Input / Output


Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...