From 4b6dea6b9151849f7d232b326bc84115520c2b87 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Sat, 17 Jan 2026 14:41:19 +0000 Subject: [PATCH] [Sync Iteration] c/largest-series-product/1 --- .../1/largest_series_product.c | 25 +++++++++++++++++++ .../1/largest_series_product.h | 9 +++++++ 2 files changed, 34 insertions(+) create mode 100644 solutions/c/largest-series-product/1/largest_series_product.c create mode 100644 solutions/c/largest-series-product/1/largest_series_product.h diff --git a/solutions/c/largest-series-product/1/largest_series_product.c b/solutions/c/largest-series-product/1/largest_series_product.c new file mode 100644 index 0000000..b993faa --- /dev/null +++ b/solutions/c/largest-series-product/1/largest_series_product.c @@ -0,0 +1,25 @@ +#include "largest_series_product.h" +#include +#include +#include +#include + +int64_t largest_series_product(char *digits, size_t span){ + if (!digits || span == 0) return -1; + + size_t len = strlen(digits); + if (span > len) return -1; + + int64_t max = 0; + + for (size_t i = 0, out_limit = len - span + 1; i < out_limit; i++) { + int64_t n = 1; + for (size_t j = i, in_limit = i + span; j < len && j < in_limit; j++) { + if (digits[j] >= '0' && digits[j] <= '9') n *= digits[j] - '0'; + else return -1; + } + if (n > max) max = n; + } + + return max; +} diff --git a/solutions/c/largest-series-product/1/largest_series_product.h b/solutions/c/largest-series-product/1/largest_series_product.h new file mode 100644 index 0000000..39a9258 --- /dev/null +++ b/solutions/c/largest-series-product/1/largest_series_product.h @@ -0,0 +1,9 @@ +#ifndef LARGEST_SERIES_PRODUCT_H +#define LARGEST_SERIES_PRODUCT_H + +#include +#include + +int64_t largest_series_product(char *digits, size_t span); + +#endif