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

This commit is contained in:
Vladyslav Korzun 2023-03-06 17:09:13 +00:00
parent ba3e148434
commit b2f5720625

View File

@ -5,73 +5,67 @@
#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);
pos++; pos++;
if (r == NULL || !isdigit(*r) || *r == EOF) { if (r == NULL || !isdigit(*r)) {
//printf("%d", *r); //printf("%d", *r);
if(*r == 10 || r == NULL){ if(*r == 10){
stop = 1; stop = 1;
} }
else{ else{
if(pos > 0){ if(pos > 0){
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", pos); printf("Nepodarilo sa nacitat polynom na %d mieste.\n", pos);
return 0; return 0;
} }
else{ else{
printf("Nepodarilo sa nacitat zaklad x\n"); printf("Nepodarilo sa nacitat zaklad x\n");
return 0; return 0;
} }
} }
} }
else if (*r == EOF) { r2 = atof(riadok);
stop = 1; mass[i] = r2;
} //printf("%.2f\n", r2);
else { i++;
r2 = atof(riadok); //printf("%d\n", i);
mass[i] = r2; }
//printf("%.2f\n", r2); x = mass[0];
i++; vysl = x;
//printf("%d\n", i); //printf("%d\n", x);
} if(i != 3){
} for(int j = 1; j < i - 1; j++){
x = mass[0]; h = mass[j];
vysl = x; //printf("h>>> %1.f\n", h);
//printf("%d\n", x); if(counter == -1){
if(i != 3){ vysl = x * h + mass[j + 1];
for(int j = 1; j < i - 1; j++){ //printf("vysl>>> %1.f\n", vysl);
h = mass[j]; counter++;
//printf("h>>> %1.f\n", h); }
if(counter == -1){ else{
vysl = x * h + mass[j + 1]; if(j != i - 2){
//printf("vysl>>> %1.f\n", vysl); vysl = x * vysl + mass[j + 1];
counter++; //printf("vysl22>>>>> %1.f\n", vysl);
} }
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);
} }
else{
vysl = mass[1];
}
printf("Vysledok je: %.2f\n", vysl);
}