From 82ab3a18a3e6d30fd6754ecc058e49d9c26abd90 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 18:39:16 +0000 Subject: [PATCH] refactoring: if there is only one number just return that one as the average --- src/average_median/average_median.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/average_median/average_median.c b/src/average_median/average_median.c index 968160e..2d3422d 100644 --- a/src/average_median/average_median.c +++ b/src/average_median/average_median.c @@ -7,6 +7,9 @@ double average(const double *data, int n) { if (n==0) { return 0; } + else if (n==1){ + return data[0]; + } else { double sum = 0.0; for (int i = 0; i < n; ++i) {