From 532c5cede2173725ddd313978faa80049e578602 Mon Sep 17 00:00:00 2001 From: Miloslav Macko Date: Thu, 7 Mar 2024 13:14:00 +0100 Subject: [PATCH] 1 --- cv3/program.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index a17fe80..bef5560 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -12,21 +12,19 @@ double evaluate_polynomial(double x, double coefficients[], int degree) { } int main() { - double x; - if (scanf("%lf", &x) != 1) { - printf("Chyba: Neplatná hodnota x.\n"); - return 1; - } - - double coefficients[MAX_COEFFICIENTS]; int degree; - printf("Zadajte stupeň polynómu: "); - if (scanf("%d", °ree) != 1 || degree < 0 || degree >= MAX_COEFFICIENTS) { + if (scanf("%d", °ree) != 1 || degree < 0) { printf("Chyba: Neplatný stupeň polynómu.\n"); return 1; } + + if (degree >= MAX_COEFFICIENTS) { + printf("Chyba: Príliš vysoký stupeň polynómu.\n"); + return 1; + } + double coefficients[MAX_COEFFICIENTS]; printf("Zadajte koeficienty polynómu: "); for (int i = 0; i <= degree; i++) { if (scanf("%lf", &coefficients[i]) != 1) { @@ -35,8 +33,15 @@ int main() { } } + double x; + printf("Zadajte hodnotu x: "); + if (scanf("%lf", &x) != 1) { + printf("Chyba: Neplatná hodnota x.\n"); + return 1; + } + double result = evaluate_polynomial(x, coefficients, degree); - printf("Vysledok je: %.2f\n", result); + printf("Výsledok je: %.2f\n", result); return 0; }