This commit is contained in:
Macko 2024-03-07 13:14:00 +01:00
parent 1ba46cee88
commit 532c5cede2

View File

@ -12,21 +12,19 @@ double evaluate_polynomial(double x, double coefficients[], int degree) {
}
int main() {
double x;
if (scanf("%lf", &x) != 1) {
printf("Chyba: Neplatná hodnota x.\n");
return 1;
}
double coefficients[MAX_COEFFICIENTS];
int degree;
printf("Zadajte stupeň polynómu: ");
if (scanf("%d", &degree) != 1 || degree < 0 || degree >= MAX_COEFFICIENTS) {
if (scanf("%d", &degree) != 1 || degree < 0) {
printf("Chyba: Neplatný stupeň polynómu.\n");
return 1;
}
if (degree >= MAX_COEFFICIENTS) {
printf("Chyba: Príliš vysoký stupeň polynómu.\n");
return 1;
}
double coefficients[MAX_COEFFICIENTS];
printf("Zadajte koeficienty polynómu: ");
for (int i = 0; i <= degree; i++) {
if (scanf("%lf", &coefficients[i]) != 1) {
@ -35,8 +33,15 @@ int main() {
}
}
double x;
printf("Zadajte hodnotu x: ");
if (scanf("%lf", &x) != 1) {
printf("Chyba: Neplatná hodnota x.\n");
return 1;
}
double result = evaluate_polynomial(x, coefficients, degree);
printf("Vysledok je: %.2f\n", result);
printf("Výsledok je: %.2f\n", result);
return 0;
}