From 7a01d6400b5738ce6f5532401449ac8bfb7a1649 Mon Sep 17 00:00:00 2001 From: PavanaSakethaRam <125014811+PavanaSakethaRam@users.noreply.github.com> Date: Sat, 7 Oct 2023 10:44:29 +0530 Subject: [PATCH] Create 93lHvP.cs Signed-off-by: PavanaSakethaRam <125014811+PavanaSakethaRam@users.noreply.github.com> --- r6uCMh/93lHvP.cs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 r6uCMh/93lHvP.cs diff --git a/r6uCMh/93lHvP.cs b/r6uCMh/93lHvP.cs new file mode 100644 index 0000000..7c38ad4 --- /dev/null +++ b/r6uCMh/93lHvP.cs @@ -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}"); + } +}