39 lines
799 B
C
39 lines
799 B
C
#include <stdio.h>
|
|
|
|
#define MAX_COEFFICIENTS 100
|
|
|
|
double evaluatePolynomial(double x, double coefficients[], int n) {
|
|
double result = 0.0;
|
|
for (int i = 0; i < n; ++i) {
|
|
result = result * x + coefficients[i];
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int main() {
|
|
double x, coef;
|
|
double coefficients[MAX_COEFFICIENTS];
|
|
int count = 0;
|
|
|
|
if (scanf("%lf", &x) != 1) {
|
|
printf("Nepodarilo sa nacitat hodnotu x.\n");
|
|
return 0;
|
|
}
|
|
|
|
while (scanf("%lf", &coef) == 1) {
|
|
coefficients[count++] = coef;
|
|
}
|
|
|
|
|
|
if (!feof(stdin)) {
|
|
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", count + 1);
|
|
return 0;
|
|
}
|
|
|
|
double result = evaluatePolynomial(x, coefficients, count);
|
|
printf("Vysledok je: %.2f\n", result);
|
|
|
|
return 0;
|
|
}
|
|
|