Skip to content

Commit

Permalink
Fixes smuos#3. Created a median function
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiPushOrigin committed Oct 2, 2014
1 parent 28c94e9 commit c14b884
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ int numcmp (const void *a, const void *b) {

float mean (int* values, int length) { //float function to calculate upto two decimal places
float sum = 0;
for (int i=0; i<ength; i++) {
for (int i = 0; i < ength; i++) {
sum +=values[i];
}
return sum / length;
}

float median (int* values, int length) {
int middle = length / 2;
if (length % 2 == 0) { //check if the total number is even/odd
return(values[middle - 1] + values[middle]) / 2;
} else {
return values[middle];
}


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

Expand Down

0 comments on commit c14b884

Please sign in to comment.