From e24c13ad36c9fd6c5911c8eb03cfe677ed2c79b6 Mon Sep 17 00:00:00 2001 From: Denis Landa Date: Fri, 7 Mar 2025 00:16:39 +0100 Subject: [PATCH] 1 --- du2/program.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 du2/program.c diff --git a/du2/program.c b/du2/program.c new file mode 100644 index 0000000..66f9d51 --- /dev/null +++ b/du2/program.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +#define LINE_SIZE 100 + +int main(){ + char line[LINE_SIZE]; + float x; + float coefficients[50]; + int count = 0; + + if(fgets(line, LINE_SIZE, stdin) == NULL) { + printf("Chyba: Nepodarilo sa nacitat hodnotu x.\n"); + return 1; + } + x = strtof(line, NULL); + + while (fgets(line, LINE_SIZE, stdin) != NULL) { + if (strlen(line) == 1) + break; + float coef = strtof(line, NULL); + coefficients[count++] = coef; + } + + if(count == 0){ + printf("Chyba: Nepodarilo sa nacitat koeficienty.\n"); + return 1; + } + + float result = coefficients[0]; + for (int i = 1; i < count; i++) { + result = result * x + coefficients[i]; + } + + printf("Vysledok je: %.2f\n", result); + return 0; +} +