2025-02-25 14:00:04 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2025-02-25 14:09:29 +00:00
|
|
|
void evaluate_polynomial(double x, double *coefficients, int n) {
|
|
|
|
double result = coefficients[0];
|
|
|
|
|
|
|
|
// Применение метода Хорнера
|
|
|
|
for (int i = 1; i < n; i++) {
|
|
|
|
result = result * x + coefficients[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Vysledok je: %.2f\n", result);
|
|
|
|
}
|
2025-02-25 14:00:04 +00:00
|
|
|
|
|
|
|
int main() {
|
2025-02-25 14:09:29 +00:00
|
|
|
double x;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
// Ввод значения x
|
2025-02-25 14:00:04 +00:00
|
|
|
if (scanf("%lf", &x) != 1) {
|
2025-02-25 14:09:29 +00:00
|
|
|
printf("Chyba: Neplatne x\n");
|
2025-02-25 14:00:04 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2025-02-25 14:09:29 +00:00
|
|
|
|
|
|
|
double coefficients[100]; // Массив для коэффициентов полинома
|
|
|
|
|
|
|
|
// Чтение коэффициентов
|
|
|
|
while (scanf("%lf", &coefficients[n]) == 1) {
|
|
|
|
n++;
|
2025-02-25 14:00:04 +00:00
|
|
|
}
|
2025-02-25 14:09:29 +00:00
|
|
|
|
|
|
|
// Если нет коэффициентов
|
|
|
|
if (n == 0) {
|
|
|
|
printf("Chyba: Nebyly zadany koeficienty\n");
|
2025-02-25 14:00:04 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2025-02-25 14:09:29 +00:00
|
|
|
|
|
|
|
// Вызов функции для вычисления полинома
|
|
|
|
evaluate_polynomial(x, coefficients, n);
|
|
|
|
|
2025-02-25 14:00:04 +00:00
|
|
|
return 0;
|
2025-02-25 14:06:18 +00:00
|
|
|
}
|