From 0941ced661775e57c62189a3bfe0e95d8b2cc2f7 Mon Sep 17 00:00:00 2001 From: Bohdana Marchenko Date: Thu, 6 Mar 2025 11:14:11 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20du2/program.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du2/program.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/du2/program.c b/du2/program.c index 20eceda..2ee8b90 100644 --- a/du2/program.c +++ b/du2/program.c @@ -26,6 +26,7 @@ int read_double(double *value, int coef_index) { // If no number was read or there are invalid characters if (endptr == line || *endptr != '\0') { + printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index); // Correct error message return -1; // Indicate error } @@ -47,12 +48,11 @@ int main() { double coef; double result = 0; - int coef_count = 0; // Start counting coefficients from 0 + int coef_count = 1; // Start from the first coefficient (x^1) // Loop to read coefficients while (1) { - coef_count++; // Increase coefficient index for each input - status = read_double(&coef, coef_count); + status = read_double(&coef, coef_count + 1); // coef_count + 1 for correct indexing if (status == -1) { return 0; // Exit program if there's invalid input @@ -66,6 +66,7 @@ int main() { } result = result * x + coef; // Apply Horner's method for polynomial evaluation + coef_count++; } // Print the result