Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zekewang918 committed Sep 27, 2014
1 parent 613ca47 commit ce7d277
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,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<length;i++){
sum += num[i];
}
// Return mean
return sum/length;
}

// Median function that outputs median
float median(int *num, int length){
// If the length of array is even
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 num[length/2+1];
}
}
Expand Down
2 changes: 1 addition & 1 deletion mm.c~
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ float mean(int *num, int length) {

float median(int *num, int length){
if(length%2==0){
return (num[length/2]+num[length/2+1])/(float)2;
return (num[length/2-1]+num[length/2])/(float)2;
}else{
return num[length/2+1];
}
Expand Down

0 comments on commit ce7d277

Please sign in to comment.