diff --git a/du2/program.c b/du2/program.c new file mode 100644 index 0000000..f36dd9e --- /dev/null +++ b/du2/program.c @@ -0,0 +1,36 @@ +#include + +int main() { + double x, koeficient, vysledok = 0; + int index = 1; + + // Nacitanie x + if (scanf("%lf", &x) != 1) { + printf("Chyba: Neplatná hodnota pre x.\n"); + return 1; + } + + // 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 + } + + vysledok = koeficient; + index++; + + // Čítanie ďalších koeficientov + while (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)) { + printf("Nepodarilo sa nacitat polynom na %d mieste.\n", index); + return 0; // Zmenené z return 1 na return 0 + } + + printf("Vysledok je: %.2f\n", vysledok); + return 0; +}