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

This commit is contained in:
Bohdana Marchenko 2025-03-06 13:04:49 +00:00
parent 29baf2a6fe
commit 2e265581c9

View File

@ -12,8 +12,10 @@ int read_double(double *value, int coef_index) {
return 0;
}
line[strcspn(line, "\r\n")] = 0;
if (strlen(line) == 0) {
return 0;
}
@ -21,12 +23,9 @@ int read_double(double *value, int coef_index) {
char *endptr;
*value = strtod(line, &endptr);
if (endptr == line || *endptr != '\0') {
if (coef_index == 1) {
printf("Nepodarilo sa nacitat zaklad x\n");
} else {
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index);
}
return -1;
}
@ -36,7 +35,6 @@ int read_double(double *value, int coef_index) {
int main() {
double x;
// Read base `x`
if (!read_double(&x, 1)) {
return 1;
}
@ -47,7 +45,6 @@ int main() {
while (1) {
coef_count++;
int status = read_double(&coef, coef_count);
if (status == -1) {
@ -64,6 +61,7 @@ int main() {
result = result * x + coef;
}
printf("Vysledok je: %.2f\n", result);
return 0;
}