Aktualizovat du2/program.c

This commit is contained in:
Denys Sanchuk 2025-03-04 13:29:42 +00:00
parent c92b1885f0
commit 8076194fab

View File

@ -1,6 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
int je_cislo(const char *str) {
char *endptr;
@ -14,7 +16,7 @@ double citaj_cislo(int poradie) {
if (poradie == 0) {
fprintf(stderr, "Chyba: Nepodarilo sa nacitat hodnotu x.\n");
} else {
fprintf(stderr, "Chyba: Nepodarilo sa nacitat koeficient c.%d.\n", poradie);
fprintf(stderr, "Nepodarilo sa nacitat polynom na %d mieste.\n", poradie);
}
exit(1);
}
@ -23,14 +25,14 @@ double citaj_cislo(int poradie) {
if (newline) *newline = '\0';
if (buffer[0] == '\0') {
return 0.0 / 0.0;
return NAN;
}
if (!je_cislo(buffer)) {
if (poradie == 0) {
fprintf(stderr, "Chyba: Nepodarilo sa nacitat hodnotu x.\n");
} else {
fprintf(stderr, "Chyba: Nepodarilo sa nacitat koeficient c.%d.\n", poradie);
fprintf(stderr, "Nepodarilo sa nacitat polynom na %d mieste.\n", poradie);
}
exit(1);
}
@ -55,7 +57,7 @@ int main() {
while (1) {
double koeficient = citaj_cislo(n + 1);
if (koeficient != koeficient) {
if (isnan(koeficient)) {
break;
}
koef[n++] = koeficient;