41 lines
827 B
C
41 lines
827 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <math.h>
|
||
|
|
||
|
#define LINE_SIZE 100
|
||
|
|
||
|
int main(){
|
||
|
char line[LINE_SIZE];
|
||
|
float x;
|
||
|
float coefficients[50];
|
||
|
int count = 0;
|
||
|
|
||
|
if(fgets(line, LINE_SIZE, stdin) == NULL) {
|
||
|
printf("Chyba: Nepodarilo sa nacitat hodnotu x.\n");
|
||
|
return 1;
|
||
|
}
|
||
|
x = strtof(line, NULL);
|
||
|
|
||
|
while (fgets(line, LINE_SIZE, stdin) != NULL) {
|
||
|
if (strlen(line) == 1)
|
||
|
break;
|
||
|
float coef = strtof(line, NULL);
|
||
|
coefficients[count++] = coef;
|
||
|
}
|
||
|
|
||
|
if(count == 0){
|
||
|
printf("Chyba: Nepodarilo sa nacitat koeficienty.\n");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
float result = coefficients[0];
|
||
|
for (int i = 1; i < count; i++) {
|
||
|
result = result * x + coefficients[i];
|
||
|
}
|
||
|
|
||
|
printf("Vysledok je: %.2f\n", result);
|
||
|
return 0;
|
||
|
}
|
||
|
|