c# odd even median
C#
public static void Main(string[] args)
{
int[] a = { 1, 4, 5, 8, 19, 12, 15 };
List<int> l = new List<int>(a); l.Sort();
List<int> even = new List<int>(); //hold even numbers
List<int> odd = new List<int>(); //hold odd numbers
int medianOdd;
int medianEven;
foreach (int num in l)
{
if (num % 2 == 0) even.Add(num);
else odd.Add(num);
} //formula for median with odd vs even total length
if (even.Count % 2 != 0) medianEven = even[even.Count / 2];
else medianEven = (even[(even.Count - 1) / 2] + even[even.Count / 2]) / 2;
if (odd.Count % 2 != 0) medianOdd = odd[odd.Count / 2];
else medianOdd = (odd[(odd.Count - 1) / 2] + odd[odd.Count / 2]) / 2;
Console.Write($"Even Median = {medianEven} Odd Median = {medianOdd}");
//median w/ Odd total length = length/2 vs Even length = ( (length/2 -1) + (length/2) ) /2
}
Also in C#:
- Title
- question mark operator in c#
- Category
- C#
- Title
- start a particle effect when a button is pushed
- Category
- C#
- Title
- c# httpclient azure function authorization
- Category
- C#
- Title
- c# image to byte array
- Category
- C#
- Title
- unity key detection
- Category
- C#
- Title
- c# array to list
- Category
- C#
- Title
- unity fps counter
- Category
- C#
- Title
- blazor display validation message
- Category
- C#
- Title
- convert from xls to xlsx C#
- Category
- C#
- Title
- unity docs player input
- Category
- C#
- Title
- unity remove gameobject
- Category
- C#
- Title
- c# get current directory xamarin
- Category
- C#
- Title
- resize image c#
- Category
- C#
- Title
- c# thread sleep
- Category
- C#
- Title
- c# console delay
- Category
- C#
- Title
- check for collision unity c#
- Category
- C#
- Title
- C# check many strings quickly
- Category
- C#
- Title
- c# region tag
- Category
- C#
- Title
- unity 2d platformer movement script c#
- Category
- C#
- Title
- wpf get name of clicked element
- Category
- C#
- Title
- dictionary c#
- Category
- C#
- Title
- linq foreach c#
- Category
- C#
- Title
- image filter
- Category
- C#
- Title
- get hash c#
- Category
- C#
- Title
- how to access first child of parent unity
- Category
- C#
- Title
- how to make an array in csharp
- Category
- C#
- Title
- c# create new object
- Category
- C#
- Title
- c# shorten an method
- Category
- C#
- Title
- get enum value c#
- Category
- C#
- Title
- uwp file open picker
- Category
- C#
- Title
- c# nullable generic
- Category
- C#
- Title
- c# remove time in datetime
- Category
- C#
- Title
- how to make an object move in unity
- Category
- C#
- Title
- error CS0542
- Category
- C#
- Title
- while loop c#
- Category
- C#
- Title
- isprime c#
- Category
- C#
- Title
- idbset sqlquery
- Category
- C#
- Title
- vb.net tostring numeric format string
- Category
- C#
- Title
- unity list
- Category
- C#
- Title
- iterate through dictionary c#
- Category
- C#
- Title
- mongodb custom IIdGenerator
- Category
- C#
- Title
- c# math to radiant
- Category
- C#
- Title
- c# create array of int
- Category
- C#
- Title
- unity getcomponent
- Category
- C#
- Title
- c# checksum
- Category
- C#
- Title
- unity accessing 2d pointlight from c# script
- Category
- C#
- Title
- socket in c#
- Category
- C#
- Title
- unity make a int arry with preset values
- Category
- C#
- Title
- count the number of notes in a given amount c#
- Category
- C#
- Title
- unity detect any key
- Category
- C#
- Title
- mvc c# w3schools
- Category
- C#
- Title
- assign datasource to dropdownlist in c#
- Category
- C#
- Title
- loops in coding
- Category
- C#
- Title
- displayname c#
- Category
- C#
- Title
- list clone - C#
- Category
- C#
- Title
- and unity
- Category
- C#
- Title
- unity string format time
- Category
- C#
- Title
- unity c# public all codes
- Category
- C#
- Title
- c# odd even median
- Category
- C#
- Title
- c# declare an int list
- Category
- C#
- Title
- unity if gameobject exists
- Category
- C#
- Title
- unity change the source image or image
- Category
- C#
- Title
- what is type unity
- Category
- C#
- Title
- import regex c#
- Category
- C#
- Title
- linq in c#
- Category
- C#
- Title
- movement script c#
- Category
- C#
- Title
- F# convert generic.List to list
- Category
- C#
- Title
- unity set material
- Category
- C#
- Title
- c# print
- Category
- C#
- Title
- .net core get image from url
- Category
- C#
- Title
- mysql executeScalar only if successful
- Category
- C#
- Title
- c# code snippet template
- Category
- C#
- Title
- how to use K2 games Games parallax background
- Category
- C#
- Title
- unity serializefield
- Category
- C#
- Title
- get user directory of file in c#
- Category
- C#
- Title
- center an image horizontally and vertically
- Category
- C#
- Title
- unity main texture not working
- Category
- C#
- Title
- c# object clone
- Category
- C#
- Title
- c# mathf.ceiling
- Category
- C#
- Title
- how to change player cursor c# script unity
- Category
- C#
- Title
- how to reload app.config file at runtime in c#
- Category
- C#
- Title
- unity get data from firebase
- Category
- C#
- Title
- select a whole row out of a 2d array C#
- Category
- C#
- Title
- c# keyvaluepair
- Category
- C#
- Title
- open zip file in c#
- Category
- C#
- Title
- c# string array
- Category
- C#
- Title
- unity find object by name
- Category
- C#
- Title
- c# MD5.Create returning nul
- Category
- C#
- Title
- xml node update attribute value c#
- Category
- C#
- Title
- how to add a componet to a gameobject throgh code unity
- Category
- C#
- Title
- find month number from date C#
- Category
- C#
- Title
- nullreferenceexception c#
- Category
- C#
- Title
- unity delete specific text in a string
- Category
- C#
- Title
- unity set material color
- Category
- C#
- Title
- freeze position unity c#
- Category
- C#
- Title
- sum the digits in c#
- Category
- C#
- Title
- unity c# is not equal to
- Category
- C#
- Title
- unity hide mouse first person
- Category
- C#
- Title
- how can convert string to int csharp
- Category
- C#
- Title
- c# how to exit program
- Category
- C#