From fb5231595e50beccbeeeb00451797dbbaacad72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ka=C4=8Dm=C3=A1r?= Date: Thu, 6 Mar 2025 14:44:57 +0000 Subject: [PATCH] Update du2/program.c --- du2/program.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/du2/program.c b/du2/program.c index 9895d24..a2a9363 100644 --- a/du2/program.c +++ b/du2/program.c @@ -3,6 +3,7 @@ int main() { double x, koeficient, vysledok = 0; int index = 1; + int nacitane; // Nacitanie x if (scanf("%lf", &x) != 1) { @@ -13,24 +14,24 @@ int main() { // Nacitanie prvého koeficientu if (scanf("%lf", &koeficient) != 1) { printf("Nepodarilo sa nacitat polynom na %d mieste.\n", index); - return 0; // Zmenené z return 1 na return 0 + return 0; } vysledok = koeficient; index++; // Čítanie ďalších koeficientov - while (scanf("%lf", &koeficient) == 1) { + while ((nacitane = scanf("%lf", &koeficient)) == 1) { vysledok = vysledok * x + koeficient; index++; } // Ak posledné čítanie zlyhalo a nebol to EOF, znamená to nečíselný vstup - if (!feof(stdin)) { + if (nacitane == 0) { printf("Nepodarilo sa nacitat polynom na %d mieste.\n", index); - return 0; // Zmenené z return 1 na return 0 + return 0; } printf("Vysledok je: %.2f\n", vysledok); return 0; -} +} \ No newline at end of file