diff --git a/du3/program.c b/du3/program.c index 9fb6dfd..ff22c30 100644 --- a/du3/program.c +++ b/du3/program.c @@ -5,71 +5,73 @@ #include #include #define LINE_SIZE 150 + int main(){ - char riadok[LINE_SIZE]; - memset(riadok, 0,LINE_SIZE); - char* r; - float r2; - int stop = 0; - float mass[LINE_SIZE]; - int i = 0; - float x = 0; - float vysl = 0; - int counter = -1; - float h = 0; - int pos = -1; - //float p = 0; - while(stop == 0){ - r = fgets(riadok,LINE_SIZE,stdin); - if(feof(stdin)){ - break; - } - pos++; - - if (r == NULL || !isdigit(*r) || *r == EOF || feof(stdin)) { - //printf("%d", *r); - if(*r == 10){ - stop = 1; - } - else{ - if(pos > 0){ - printf("Nepodarilo sa nacitat polynom na %d mieste.\n", pos); - return 0; - } - else{ - printf("Nepodarilo sa nacitat zaklad x\n"); - return 0; - } - } - } - r2 = atof(riadok); - mass[i] = r2; - //printf("%.2f\n", r2); - i++; - //printf("%d\n", i); - } - x = mass[0]; - vysl = x; - //printf("%d\n", x); - if(i != 3){ - for(int j = 1; j < i - 1; j++){ - h = mass[j]; - //printf("h>>> %1.f\n", h); - if(counter == -1){ - vysl = x * h + mass[j + 1]; - //printf("vysl>>> %1.f\n", vysl); - counter++; - } - else{ - if(j != i - 2){ - vysl = x * vysl + mass[j + 1]; - //printf("vysl22>>>>> %1.f\n", vysl); - } - } - } - } - else{ - vysl = mass[1]; - } - printf("Vysledok je: %.2f\n", vysl); + char riadok[LINE_SIZE]; + memset(riadok, 0,LINE_SIZE); + char* r; + float r2; + int stop = 0; + float mass[LINE_SIZE]; + int i = 0; + float x = 0; + float vysl = 0; + int counter = -1; + float h = 0; + int pos = -1; + //float p = 0; + while(stop == 0){ + r = fgets(riadok,LINE_SIZE,stdin); + pos++; + if (r == NULL || !isdigit(*r) || *r == EOF) { + //printf("%d", *r); + if(*r == 10 || r == NULL){ + stop = 1; + } + else{ + if(pos > 0){ + printf("Nepodarilo sa nacitat polynom na %d mieste.\n", pos); + return 0; + } + else{ + printf("Nepodarilo sa nacitat zaklad x\n"); + return 0; + } + } + } + else if (*r == EOF) { + stop = 1; + } + else { + r2 = atof(riadok); + mass[i] = r2; + //printf("%.2f\n", r2); + i++; + //printf("%d\n", i); + } + } + x = mass[0]; + vysl = x; + //printf("%d\n", x); + if(i != 3){ + for(int j = 1; j < i - 1; j++){ + h = mass[j]; + //printf("h>>> %1.f\n", h); + if(counter == -1){ + vysl = x * h + mass[j + 1]; + //printf("vysl>>> %1.f\n", vysl); + counter++; + } + else{ + if(j != i - 2){ + vysl = x * vysl + mass[j + 1]; + //printf("vysl22>>>>> %1.f\n", vysl); + } + } + } + } + else{ + vysl = mass[1]; + } + printf("Vysledok je: %.2f\n", vysl); }