Search
 
SCRIPT & CODE EXAMPLE
 

C

c median of an array

//function that receives an array and it's number of elements as ints
//and outputs the array's median value as a float
float CalcMedian(int ar[], int arraySize)
{
    float median;

    if(arraySize % 2 == 0){
    	 //2.0 needs the decimal value so it doesn't truncate the result
        median = (ar[(arraySize-1) / 2] + ar[arraySize/2]) / 2.0;
    }else{
        median = ar[arraySize/2];
    }

    return median;
}
Comment

PREVIOUS NEXT
Code Example
Javascript ::  
Javascript ::  
::  
::  
::  
::  
::  
Javascript ::  
::  
::  
::  
::  
::  
::  
::  
::  
::  
::  
::  
::  
Javascript ::  
Javascript :: how to get the first key in a n object in javascript 
::  
::  
Javascript :: Javascript get random item from array 
Javascript ::  
::  
::  
::  
::  
ADD CONTENT
Topic
Content
Source link
Name
9+8 =