From ee611880aaad06e7fe61107fbc4c233fca4a7e38 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 18:38:08 +0000 Subject: [PATCH] refactoring: just return 0 if the data is empty for the average --- src/average_median/average_median.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/average_median/average_median.c b/src/average_median/average_median.c index 8fb03c8..968160e 100644 --- a/src/average_median/average_median.c +++ b/src/average_median/average_median.c @@ -4,11 +4,16 @@ #include double average(const double *data, int n) { + if (n==0) { + return 0; + } + else { double sum = 0.0; for (int i = 0; i < n; ++i) { sum += data[i]; } return sum / n; + } } double median(double *data, int n) {