From d87e7f21a912a009eb0095776dec1e57cc3c6aaf Mon Sep 17 00:00:00 2001 From: Patrik Seman Date: Sat, 11 Mar 2023 11:46:52 +0100 Subject: [PATCH] . --- du2/program.c | 4 ++-- du3/program.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 du3/program.c diff --git a/du2/program.c b/du2/program.c index 79c81b3..422c440 100644 --- a/du2/program.c +++ b/du2/program.c @@ -12,8 +12,8 @@ int main(){ int max_hrac = 0; int value = 0; int r = 0; - int najlepsi[VELKOST_POLA]; - int k=0; + //int najlepsi[VELKOST_POLA]; + //int k=0; while(i < VELKOST_POLA){ value = 0; r = scanf("%d", &value); diff --git a/du3/program.c b/du3/program.c new file mode 100644 index 0000000..3b19a60 --- /dev/null +++ b/du3/program.c @@ -0,0 +1,39 @@ +#include +#include + +#define LINE_SIZE 10 + +int main(){ + + float line[LINE_SIZE]; + int count; + char buffer[50]; + + for(count = 0; count < LINE_SIZE; count++){ + + if(fgets(buffer, 50, stdin) == NULL || buffer[0] == '\n'){ + break; + } + + int success = sscanf(buffer, "%f", &line[count]); + + if(success == 0 || success == EOF){ + if(count == 0){ + printf("Nepodarilo sa nacitat x.\n"); + }else{ + printf("Nepodarilo sa nacitat %d. koeficient\n", count); + } + return 0; + } + } + + float result = 0; + float x = line[0]; + + for(int i = 1; i < count; i++){ + result = result * x + line[i]; + } + + printf("Vysledok je: %.2f\n", result); + +}