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; }