Skip to content

Commit

Permalink
fixed smuos#3 which is add a function, median(), to mm.c to calculate…
Browse files Browse the repository at this point in the history
… the median
  • Loading branch information
Yumingz committed Sep 29, 2014
1 parent 70c0f7e commit 55899b6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ double mean(int* num, int size) {
return mean;
}

// Find median
int median(int* num, int size) {
// Declare variable
int middle;
double median;
middle = size / 2.0;
// If there are even numbers of an array
if (size % 2) {
median = (num[middle]+num[middle+1])/2.0;
}
// If array is odd
else {
median = num[middle];
}
return median;
}


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

int i, length, *pt;
Expand Down

0 comments on commit 55899b6

Please sign in to comment.