Skip to content

Commit

Permalink
function to calculate median is added which fixes smuos#3
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuha99 committed Oct 1, 2014
1 parent 814bb2e commit b2f07e7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ float mean(const int* a, int n){
return avg;
}

// function to calculate median
float median(const int* a, int n){
float med = 0;

if(n % 2 == 0)
med = ( a[n/2-1] + a[n/2] ) / 2.0;
else
med = a[n/2];

return med;
}

int main(int argc, char *argv[]) {

int i, length, *pt;
Expand Down

0 comments on commit b2f07e7

Please sign in to comment.