pvjc23/du3/program.c

101 lines
1.0 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#define LINE_SIZE 10
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;
while(stop == 0){
r = fgets(riadok,LINE_SIZE,stdin);
assert(r!=NULL);
r2 = atof(riadok);
mass[i] = r2;
//printf("%.2f\n", r2);
i++;
if (r2 == 0){
//printf("Konverzia sa nepodarila alebo v reťazci sa nachádza nula.\n");
stop++;
}
}
x = mass[0];
vysl = x;
//printf("%d\n", x);
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);
}
}
}
printf("Vysledok je: %2.f\n", roundf(vysl * 100) / 100);
}