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

This commit is contained in:
Vladyslav Korzun 2023-03-02 10:39:59 +00:00
parent 5691313fc4
commit e529ce698b

View File

@ -1,100 +1,50 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#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;
//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 (r == NULL || !isdigit(*r)) { if (r == NULL || !isdigit(*r)) {
stop = 1;
break;
} }
r2 = atof(riadok); r2 = atof(riadok);
mass[i] = r2; mass[i] = r2;
//printf("%.2f\n", r2); //printf("%.2f\n", r2);
i++; i++;
} }
x = mass[0]; x = mass[0];
vysl = x; vysl = x;
//printf("%d\n", x); //printf("%d\n", x);
for(int j = 1; j < i - 1; j++){ for(int j = 1; j < i - 1; j++){
h = mass[j]; h = mass[j];
//printf("h>>> %1.f\n", h); //printf("h>>> %1.f\n", h);
if(counter == -1){ if(counter == -1){
vysl = x * h + mass[j + 1]; vysl = x * h + mass[j + 1];
//printf("vysl>>> %1.f\n", vysl); //printf("vysl>>> %1.f\n", vysl);
counter++; counter++;
} }
else{ else{
if(j != i - 2){ if(j != i - 2){
vysl = x * vysl + mass[j + 1]; vysl = x * vysl + mass[j + 1];
//printf("vysl22>>>>> %1.f\n", vysl); //printf("vysl22>>>>> %1.f\n", vysl);
} }
} }
} }
printf("Vysledok je: %.2f\n", vysl); printf("Vysledok je: %.2f\n", vysl);
} }