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