From c150aeafc09965011dd375225677cd8bc13dd500 Mon Sep 17 00:00:00 2001 From: Bohdana Marchenko Date: Thu, 6 Mar 2025 11:18:47 +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 | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/du2/program.c b/du2/program.c index 621c137..3ebd139 100644 --- a/du2/program.c +++ b/du2/program.c @@ -37,15 +37,9 @@ int main() { double x; // Read the value of x - int status = read_double(&x, 1); - if (status == -1) { - // If x is invalid, print a specific error and exit - printf("Nepodarilo sa nacitat zaklad x\n"); + if (!read_double(&x, 1)) { return 1; } - if (status == 0) { - return 1; // Exit if no input is provided - } double coef; double result = 0; @@ -54,7 +48,7 @@ int main() { // Loop to read coefficients while (1) { coef_count++; // Increase coefficient index for each input - status = read_double(&coef, coef_count + 1); // coef_count + 1 for correct indexing + int status = read_double(&coef, coef_count); if (status == -1) { return 0; // Exit program if there's invalid input @@ -67,7 +61,7 @@ int main() { break; } - result = result * x + coef; // Apply Horner's method for polynial evaluation + result = result * x + coef; // Apply Horner's method for polynomial evaluation } // Print the result