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

This commit is contained in:
Bohdana Marchenko 2025-03-06 10:43:15 +00:00
parent dc27d78f36
commit 0690bb3eba

View File

@ -5,22 +5,23 @@
#define LINE_SIZE 100
int read_double(double *value) {
int read_double(double *value, int coef_index) {
char line[LINE_SIZE];
if (fgets(line, LINE_SIZE, stdin) == NULL) {
return 0; // Chyba pri čítaní
return 0;
}
char *endptr;
*value = strtod(line, &endptr);
if (endptr == line || (*endptr != '\0' && *endptr != '\n')) {
return 0; // Neplatný vstup
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index);
return 0;
}
return 1;
}
int main() {
double x;
if (!read_double(&x)) {
if (!read_double(&x, 1)) {
printf("Chyba: Nepodarilo sa načítať hodnotu x.\n");
return 1;
}
@ -30,7 +31,7 @@ int main() {
int coef_count = 0;
while (1) {
if (!read_double(&coef)) {
if (!read_double(&coef, coef_count + 2)) {
if (coef_count == 0) {
printf("Chyba: Neboli zadané žiadne koeficienty.\n");
return 1;