From 31d38fbb2b8dd8b11efae8bbde71fd623a852531 Mon Sep 17 00:00:00 2001 From: jcsl94 Date: Thu, 25 Sep 2014 17:10:34 -0300 Subject: [PATCH] Resolved issue #2, mean function working. --- mm.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mm.c b/mm.c index ff1779f..62643ea 100644 --- a/mm.c +++ b/mm.c @@ -3,6 +3,19 @@ #define debug 0 +//Mean calculating function +double mean(int *pt, int length) +{ + int sum = 0; + double mean = 0; + for(int i = 0; i < length; i++) + { + sum = sum + pt[i]; + } + mean = ((double)sum/length); + return mean; +} + // Comparison function for qsort() int numcmp (const void *a, const void *b) { int x = *((int*) a); @@ -48,5 +61,7 @@ int main(int argc, char *argv[]) { } fprintf(stdout, "\n%s: FIN. \n", argv[0]); + // Call mean function + fprintf(stdout, "The mean is: %.2f \n", mean(pt, length)); return 0; }