Обновить du2/program.c

This commit is contained in:
Bohdana Marchenko 2025-03-06 11:18:47 +00:00
parent 0721f3f629
commit c150aeafc0

View File

@ -37,15 +37,9 @@ int main() {
double x; double x;
// Read the value of x // Read the value of x
int status = read_double(&x, 1); if (!read_double(&x, 1)) {
if (status == -1) {
// If x is invalid, print a specific error and exit
printf("Nepodarilo sa nacitat zaklad x\n");
return 1; return 1;
} }
if (status == 0) {
return 1; // Exit if no input is provided
}
double coef; double coef;
double result = 0; double result = 0;
@ -54,7 +48,7 @@ int main() {
// Loop to read coefficients // Loop to read coefficients
while (1) { while (1) {
coef_count++; // Increase coefficient index for each input 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) { if (status == -1) {
return 0; // Exit program if there's invalid input return 0; // Exit program if there's invalid input
@ -67,7 +61,7 @@ int main() {
break; 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 // Print the result