Skip to content

Commit

Permalink
Fixes smuos#2 add a function, mean()
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiying Zhang committed Sep 30, 2014
1 parent 8f24a61 commit bb9e7b2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ int numcmp (const void *a, const void *b) {
if (x < y) return -1;
return 0;
}
//Issues#2: Add a function, mean(),to mm.c to calculate the mean
double mean (int *num, int len){
double sum = 0, mean = 0;
//using a for loop to add up all the values in input numbers
for(int i = 0; i<len ;i++){
sum = sum + num[i];
}
//Find the mean
mean = sum / len;
return mean;
}


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

Expand Down

0 comments on commit bb9e7b2

Please sign in to comment.