Изменил(а) на 'du3/program.c'

This commit is contained in:
Vladyslav Korzun 2023-03-06 17:07:57 +00:00
parent a0a40567d3
commit ba3e148434

View File

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