Search
 
SCRIPT & CODE EXAMPLE
 

C

c median of 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 :: class in oops 
C :: c program for swapping of two numbers 
C :: c double 
C :: c language float user input 
C :: pygramid program in c 
C :: include ‘<stdlib.h’ or provide a declaration of ‘exit’ 
C :: signed and unsigned in c 
C :: binary tree count number of leaves in c 
C :: how to insert elements in and array and print it in c 
C :: c assignment operators 
C :: print 100 times c 
C :: notation of positive in c 
C :: define constant c 
C :: finding characters in string 
C :: string in c 
C :: sphinx-doc 
C :: north austin weather 
C :: C Accessing Union Members 
C :: Command to compile and execute a c file program consecutively 
C :: C++ How to use enums for flags? 
C :: C Character l/O 
C :: reset c array to zero 
C :: how to stop aws alb temporarily 
C :: reading arrays from stdin c 
C :: c limit value range 
C :: Letters and Digits Total 
C :: Single-line Comments in C 
C :: write a ppm image 
C :: fread condition 
C :: bit wise operation 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =