diff --git a/mm b/mm new file mode 100755 index 0000000..a162f7c Binary files /dev/null and b/mm differ diff --git a/mm.c b/mm.c new file mode 100644 index 0000000..0e017d6 --- /dev/null +++ b/mm.c @@ -0,0 +1,112 @@ +#include +#include +#include +#include + +#define debug 0 +#define FAILURE 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) { + int x = *((int*) a); + int y = *((int*) b); + if (x > y) return 1; + if (x < y) return -1; + 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){ + // Wait for child process + int wc = wait(NULL); + // Print parent's pid, mean and FIN + fprintf(stdout, "\n%s: This is parent prcesss(pid:%d) Waited for child process %d\n", argv[0], (int)getpid(), wc); + fprintf(stdout, "%s: The mean is: %f\n", argv[0], mean(pt, length)); + fprintf(stdout, "%s: FIN. \n",argv[0]); + } + + return 0; + +} diff --git a/mm.c~ b/mm.c~ new file mode 100644 index 0000000..3544dc3 --- /dev/null +++ b/mm.c~ @@ -0,0 +1,112 @@ +#include +#include +#include +#include + +#define debug 0 +#define FAILURE 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) { + int x = *((int*) a); + int y = *((int*) b); + if (x > y) return 1; + if (x < y) return -1; + 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){ + // Wait for child process + int wc = wait(NULL); + // Print parent's pid, mean and FIN + fprintf(stdout, "\n%s: This is parent prcesss(pid:%d) Waited for child process %d\n", argv[0], (int)getpid(), wc); + fprintf(stdout, "%s: The mean is: %f\n", argv[0], mean(pt, length)); + fprintf(stdout, "%s: FIN. \n",argv[0]); + } + + return 0; + +}