Browse Source

refactoring: just return 0 if the data is empty for the average

master
fdai7968 11 months ago
parent
commit
ee611880aa
  1. 5
      src/average_median/average_median.c

5
src/average_median/average_median.c

@ -4,11 +4,16 @@
#include <math.h> #include <math.h>
double average(const double *data, int n) { double average(const double *data, int n) {
if (n==0) {
return 0;
}
else {
double sum = 0.0; double sum = 0.0;
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
sum += data[i]; sum += data[i];
} }
return sum / n; return sum / n;
}
} }
double median(double *data, int n) { double median(double *data, int n) {

Loading…
Cancel
Save