From 12d2e76858c83d0dc821c6753d605d837c01666f Mon Sep 17 00:00:00 2001 From: Weber Date: Wed, 6 Mar 2024 14:21:26 +0000 Subject: [PATCH] skuska --- cv3/program.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/cv3/program.c b/cv3/program.c index e69de29..06f1b4c 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -0,0 +1,51 @@ +#include + +int main() { + float array[50]; + int repetitions = 0; + float number = 0; + char line[100]; + int valid = 1; + +//tu sa halda x + if (fgets(line, sizeof(line), stdin) != NULL) { + if (sscanf(line, "%f", &number) == 1) { + array[repetitions] = number; + repetitions++; + } else { + printf("Nepodarilo sa nacitat zaklad x\n"); + return 1; + } + } else { + printf("Nepodarilo sa nacitat x\n"); + return 1; + } + +// tu sa halda koeficient + while (repetitions < 50) { + if (fgets(line, sizeof(line), stdin) != NULL) { + if (line[0] == '\n') { + break; + } + if (sscanf(line, "%f", &number) == 1) { + array[repetitions] = number; + repetitions++; + } else { + printf("Nepodarilo sa nacitat polynom na %d mieste.\n", repetitions); + return 1; + } + } else { + break; + } + } + +//pocty + float result = array[1]; + for (int i = 2; i < repetitions; ++i) { + result = result * array[0] + array[i]; + } + + printf("Vysledok je: %.2f\n", result); + + return 0; +}