From 1b08a156a467b65cacea21d52ea67523c9858e0d Mon Sep 17 00:00:00 2001 From: mk570rp Date: Wed, 4 Mar 2026 15:25:42 +0000 Subject: [PATCH] push --- program.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 program.c diff --git a/program.c b/program.c new file mode 100644 index 0000000..72386ea --- /dev/null +++ b/program.c @@ -0,0 +1,61 @@ +#include +#include +#include + +#define SIZE 256 +#define MAX 1000 + +int main() { + + char line[SIZE]; + char *end; + + double x; + double pole[MAX]; + int n = 0; + + /* nacitanie x */ + if (fgets(line, SIZE, stdin) == NULL) { + printf("Chyba: nepodarilo sa nacitat x.\n"); + return 1; + } + + x = strtod(line, &end); + + if (end == line) { + printf("Chyba: nepodarilo sa nacitat x.\n"); + return 1; + } + + /* nacitanie koeficientov */ + while (fgets(line, SIZE, stdin) != NULL) { + + if (line[0] == '\n') // prazdny riadok + break; + + pole[n] = strtod(line, &end); + + if (end == line) { + printf("Chyba: nepodarilo sa nacitat koeficient %d.\n", n); + return 1; + } + + n++; + } + + if (n == 0) { + printf("Chyba: nebol zadany ziadny koeficient.\n"); + return 1; + } + + /* Horner */ + double vysledok = pole[0]; + + for (int i = 1; i < n; i++) { + vysledok = vysledok * x + pole[i]; + } + + printf("%.2f\n", vysledok); + + return 0; +} \ No newline at end of file