Skip to content
This repository was archived by the owner on Oct 7, 2023. It is now read-only.

Create 93lHvP.cs #1580

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions r6uCMh/93lHvP.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;

class Program
{
static void Main(string[] args)
{
Console.Write("Enter the number of elements in the array: ");
int n = Convert.ToInt32(Console.ReadLine());

int[] arr = new int[n];

Console.WriteLine("Enter the elements of the array:");

for (int i = 0; i < n; i++)
{
Console.Write($"Element {i + 1}: ");
arr[i] = Convert.ToInt32(Console.ReadLine());
}

// Sort the array
Array.Sort(arr);

double median;

// Calculate median
if (n % 2 == 0)
median = (arr[n / 2 - 1] + arr[n / 2]) / 2.0;
else
median = arr[n / 2];

Console.WriteLine($"The median of the array is: {median}");
}
}