Skip to content

Commit

Permalink
fixed smuos#2 Added the mean function.
Browse files Browse the repository at this point in the history
  • Loading branch information
mskmatt committed Sep 25, 2014
1 parent 945275b commit 60db61a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

#define debug 0

float mean(int length, int *pt) {
int i, total=0;
for(i=0; i<length; i++) {
total=total+pt[i];
}
return ((float)total/length);
}

// Comparison function for qsort()
int numcmp (const void *a, const void *b) {
int x = *((int*) a);
Expand Down Expand Up @@ -46,6 +54,7 @@ int main(int argc, char *argv[]) {
for (i=0; i<length; i++) {
fprintf(stdout, "%d ", pt[i]);
}
fprintf(stdout, "Mean: %.2f\n", mean(length, pt));
fprintf(stdout, "\n%s: FIN. \n", argv[0]);

return 0;
Expand Down

0 comments on commit 60db61a

Please sign in to comment.