Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this Discussion credit, you need to post a unique answer to the following. T

ID: 3714433 • Letter: F

Question

For this Discussion credit, you need to post a unique answer to the following.


Think of a function, then write its definition and document what the function does. Examples that are appropriate: Check if a number is negative, if a number is even, if a number is odd. Other examples include, a function that returns the the smallest number in an array, the largest number in an array, the average of an array. 


Your answer must be unique and not from the book, so make sure you read all posted messages before you post your example.

Explanation / Answer

Calculating Median of a sorted array

float getMedian(int arr[],int n)
{
if(n%2==0)
  return (arr[n/2]+arr[(n/2)+1])/2;
else
  return arr[n/2];
}


Here we are calculating Median of a sorted array with float input

Input : Float Array and Size
Output : Median value

Required : Sorted Array
Conditions : if n is divisible by 2 that means we will take 2 center elements and then take mean of them to calculate Median
   else we will directly return the Median element


Formula for Median

when n is even : (arr[n/2]+arr[(n/2)+1])/2

example : 1.0 2.0 4.0 5.0 6.0 7.0
   n=6 , Median = 4+5/2 =4.5

when n is odd : arr[n/2]

example : 1.0 2.0 4.0 6.0 7.0
   n=6 , Median = 4.0