Обновить du2/program.c
This commit is contained in:
parent
29baf2a6fe
commit
2e265581c9
@ -12,8 +12,10 @@ int read_double(double *value, int coef_index) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
line[strcspn(line, "\r\n")] = 0;
|
line[strcspn(line, "\r\n")] = 0;
|
||||||
|
|
||||||
|
|
||||||
if (strlen(line) == 0) {
|
if (strlen(line) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -21,12 +23,9 @@ int read_double(double *value, int coef_index) {
|
|||||||
char *endptr;
|
char *endptr;
|
||||||
*value = strtod(line, &endptr);
|
*value = strtod(line, &endptr);
|
||||||
|
|
||||||
|
|
||||||
if (endptr == line || *endptr != '\0') {
|
if (endptr == line || *endptr != '\0') {
|
||||||
if (coef_index == 1) {
|
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index);
|
||||||
printf("Nepodarilo sa nacitat zaklad x\n");
|
|
||||||
} else {
|
|
||||||
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index);
|
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +35,6 @@ int read_double(double *value, int coef_index) {
|
|||||||
int main() {
|
int main() {
|
||||||
double x;
|
double x;
|
||||||
|
|
||||||
// Read base `x`
|
|
||||||
if (!read_double(&x, 1)) {
|
if (!read_double(&x, 1)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -47,7 +45,6 @@ int main() {
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
coef_count++;
|
coef_count++;
|
||||||
|
|
||||||
int status = read_double(&coef, coef_count);
|
int status = read_double(&coef, coef_count);
|
||||||
|
|
||||||
if (status == -1) {
|
if (status == -1) {
|
||||||
@ -64,6 +61,7 @@ int main() {
|
|||||||
result = result * x + coef;
|
result = result * x + coef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printf("Vysledok je: %.2f\n", result);
|
printf("Vysledok je: %.2f\n", result);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user