Browse Source

refactoring: if there is only one number just return that one as the average

master
fdai7968 11 months ago
parent
commit
82ab3a18a3
  1. 3
      src/average_median/average_median.c

3
src/average_median/average_median.c

@ -7,6 +7,9 @@ double average(const double *data, int n) {
if (n==0) { if (n==0) {
return 0; return 0;
} }
else if (n==1){
return data[0];
}
else { else {
double sum = 0.0; double sum = 0.0;
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {

Loading…
Cancel
Save