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
C :: calculate median 
C :: rfid rc522 code 
C :: function component with props 
C :: C strlen implementation 
C :: KneesDev 
C :: set all pins as output for loop 
C :: C program to input the month number and output the month name using switch statement 
C :: create point cloud from rgbd image in open3d v0.10 
C :: build a linked list in c 
C :: looping through an array in c 
C :: how to arrange a 2d array based on string length in c 
C :: prime numbers 
C :: working outside of application context 
C :: open a file in from terminal 
C :: calling of a void in c 
C :: unused variable in c 
C :: ubuntu ocaml install 
C :: pipe system call 
C :: how to check file pointers in c 
C :: como somar em C 
C :: main prototype 
C :: send an array through a pipe 
C :: until command lldb 
C :: kleiner gleich zeichen MAC 
C :: Writing tests for API requests 
C :: if statement shortcut c 
C :: get multiple c 
C :: [4,5,6] 
C :: batteries included 
C :: class to const void * 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =