32 lines
754 B
C
32 lines
754 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#define MAX_COEFFICIENTS 100
|
|
|
|
double evaluate_polynomial(double x, double coefficients[], int degree) {
|
|
double result = coefficients[degree];
|
|
for (int i = degree - 1; i >= 0; i--) {
|
|
result = result * x + coefficients[i];
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int main() {
|
|
double x;
|
|
if (scanf("%lf", &x) != 1) {
|
|
printf("Chyba: Neplatná hodnota x.\n");
|
|
return 1;
|
|
}
|
|
|
|
// Pole koeficientov
|
|
double coefficients[] = {2, 1, 1}; // Zmena koeficientov
|
|
|
|
// Počet koeficientov
|
|
int degree = sizeof(coefficients) / sizeof(coefficients[0]);
|
|
|
|
double result = evaluate_polynomial(x, coefficients, degree - 1);
|
|
printf("Vysledok je: %.2f\n", result);
|
|
|
|
return 0;
|
|
}
|