From 0087453e12c62faaad50d32fb865555e1cdc8c54 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 18:41:51 +0000 Subject: [PATCH] refactoring: return 0 for the median if it is empty --- src/average_median/average_median.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/average_median/average_median.c b/src/average_median/average_median.c index 2d3422d..0f7bca8 100644 --- a/src/average_median/average_median.c +++ b/src/average_median/average_median.c @@ -20,7 +20,10 @@ double average(const double *data, int n) { } double median(double *data, int n) { - if (n % 2 == 0) { + if (n==0) { + return 0; + } + else if (n % 2 == 0) { return (data[n / 2 - 1] + data[n / 2]) / 2.0; } else { return data[n / 2];