diff --git a/mm b/mm index 7f02c88..5fb1da5 100755 Binary files a/mm and b/mm differ diff --git a/mm.c b/mm.c index 8d60c00..9306ab1 100644 --- a/mm.c +++ b/mm.c @@ -1,7 +1,14 @@ #include #include +#include #define debug 0 +#define FAILED 1 + +// Declare Function +int numcmp (const void *a, const void *b); +float mean(int *num, int length); +float median(int *num, int length); // Comparison function for qsort() int numcmp (const void *a, const void *b) { @@ -30,12 +37,12 @@ float mean(int *num, int length) { // Median function that outputs median float median(int *num, int length){ // If the length of array is even - if(length%2==0){ + if (length%2==0){ //return the average number between two median numbers return (num[length/2-1]+num[length/2])/(float)2; // If the length of array is odd }else{ - // Return the median + // Return the median return num[length/2+1]; } } @@ -74,10 +81,24 @@ int main(int argc, char *argv[]) { for (i=0; i 0){ + fprintf(stdout, "This is parent prcesss(pid:%d)", (int)getpid()); + fprintf(stdout, "The mean is: %f", mean(pt, length)); + fprintf(stdout, "\n%s: FIN. \n",argv[0]); + } return 0; diff --git a/mm.c~ b/mm.c~ index 6c2b9bd..61ca529 100644 --- a/mm.c~ +++ b/mm.c~ @@ -1,7 +1,14 @@ #include #include +#include #define debug 0 +#define FAILED 1 + +// Declare Function +int numcmp (const void *a, const void *b); +float mean(int *num, int length); +float median(int *num, int length); // Comparison function for qsort() int numcmp (const void *a, const void *b) { @@ -12,19 +19,30 @@ int numcmp (const void *a, const void *b) { return 0; } +//Mean functiont that outputs mean of an array float mean(int *num, int length) { + // Initialization of vars + // sum -> sum of ints of array + // i -> num used for doing iteation float sum = 0; int i; + // For loop to add every number to sum for(i=0; i 0){ + fprintf(stdout, "This is parent prcesss(pid:%d)", (int)getpid()); + fprintf(stdout, "The mean is: %f", mean(pt, length)); + } + + // Print FIN fprintf(stdout, "\n%s: FIN. \n", argv[0]); return 0;