From 4eacb196efe8cb6153df0d3f83d641c6ae0f333d Mon Sep 17 00:00:00 2001 From: Yaroslav Orlianskyi Date: Fri, 18 Mar 2022 14:17:51 +0100 Subject: [PATCH] WQE --- du3/program.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/du3/program.c b/du3/program.c index 6589e2c..01ad0b7 100644 --- a/du3/program.c +++ b/du3/program.c @@ -1,26 +1,35 @@ #include +#include +#define VELKOST_POLA 52 +#define SIZE 52 int main(){ - float vxod[999]; - int i = 0; - float result = 0; - while(1){ - float value = 0; - float r = scanf("%f", &value); - if(r == 1) - vxod[i++] = value; - else if(r <= 255 && r >= 0){ - if(i != 0) - printf("Nepodarilo sa nacitat polynom na %d mieste.\n", i); - else - printf("Nepodarilo sa nacitat zaklad x\n"); + char riadok[SIZE]; + double vxod[999]; + char *endptr = NULL; + double result = 0; + int a = i; + for(int i = 0; i < size; i++){ + char* r = fgets(buffer,SIZE,stdin); + if(*r != '\n'){ + if(*r >= 0 && *r <= 255){ + if(i == 0){ + printf("Nepodarilo sa nacitat zaklad x\n"); + return 0; + }else{ + printf("Nepodarilo sa nacitat polynom na %d mieste.\n", i); + return 0; + } + } + double v = strtod(buffer,&endptr); + k[i] = v; + a = i; + }else break; - }else{ - for(int a = 1; a < i; a++) - result = vxod[0] * result + vxod[a]; - printf("Vysledok je: %.2f\n", result); - break; - } + } + for(int i = 1; i < a; i++) + result = vxod[0] * result + vxod[i]; + printf("Vysledok je: %.2f\n", result); } return 0; }