Skip to content

Commit

Permalink
Close smuos#2 calculate mean
Browse files Browse the repository at this point in the history
  • Loading branch information
Frozenfire92 committed Sep 23, 2014
1 parent ca205c8 commit f16654a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ int numcmp (const void *a, const void *b) {
return 0;
}

// Calculuate the Mean
float mean (int *numbers, int length) {
float sum = 0;
for (int i=0; i<length; i++)
{
sum += numbers[i];
}
return sum / length;
}

int main(int argc, char *argv[]) {

int i, length, *pt;
Expand Down Expand Up @@ -46,7 +56,12 @@ int main(int argc, char *argv[]) {
for (i=0; i<length; i++) {
fprintf(stdout, "%d ", pt[i]);
}

// Print Mean
float calculatedMean = mean(pt, length);
fprintf(stdout, "\n%s: Mean is: %.3f", argv[0], calculatedMean);

fprintf(stdout, "\n%s: FIN. \n", argv[0]);

return 0;
}
}

0 comments on commit f16654a

Please sign in to comment.