From b2f07e7e9e4ff46f7d7706c78f042f922dc745fd Mon Sep 17 00:00:00 2001 From: dhuha99 Date: Wed, 1 Oct 2014 12:33:09 -0300 Subject: [PATCH] function to calculate median is added which fixes #3 --- mm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mm.c b/mm.c index ff0d497..e36b5dd 100755 --- a/mm.c +++ b/mm.c @@ -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;