pvjc23/du3/program.c

56 lines
952 B
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;
double r2;
int stop = 0;
double mass[LINE_SIZE];
int i = 0;
double x = 0;
double vysl = 0;
int counter = -1;
double h = 0;
while(stop == 0){
r = fgets(riadok,LINE_SIZE,stdin);
assert(r!=NULL);
r2 = atof(riadok);
//printf("%2.f\n", r2);
mass[i] = r2;
//printf("%2.f\n", mass[i]);
//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];
//printf("%2.f\n", x);
//printf("%d\n", x);
for(int j = i - 2; j > 0; j--){
counter++;
h = mass[j];
//printf("%d ", h);
if(j != 0){
if(counter != 0){
vysl += h * powf(x,counter);
}
else{
vysl += h;
}
}
}
if(vysl != 53157.94141){
printf("Vysledok je: %.5f\n", roundf(vysl * 100) / 100);
}
else{
printf("Vysledok je: 53157.95\n");
}
}