From d5d8deff25c824a408ac308c20560a4932109ca6 Mon Sep 17 00:00:00 2001 From: VIliam Date: Wed, 28 Feb 2024 15:51:46 +0100 Subject: [PATCH] schema --- cv3/program.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 8ce63a6..a53d755 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -16,13 +16,12 @@ int main() { double result = 1; int coefficientIndex = 0; + if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) { printf("Nepodarilo sa nacitat zaklad x\n"); return 1; } - double x_base = strtod(line, NULL); - while (1) { if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) { if (line[0] == '\n') { @@ -33,16 +32,17 @@ int main() { } char *endPtr; - double coefficient = strtod(line, &endPtr); + double x = strtod(line, &endPtr); if (*endPtr != '\n' && *endPtr != '\0') { printf("Nespravny format cisla\n"); return 1; } - result = result * x_base + coefficient; + result *= x; coefficientIndex++; } printf("Vysledok je: %.2f\n", result); return 0; } +