Update du2/program.c

This commit is contained in:
Martin Kačmár 2025-03-06 14:44:57 +00:00
parent bf06b29dc9
commit fb5231595e

View File

@ -3,6 +3,7 @@
int main() {
double x, koeficient, vysledok = 0;
int index = 1;
int nacitane;
// Nacitanie x
if (scanf("%lf", &x) != 1) {
@ -13,24 +14,24 @@ int main() {
// Nacitanie prvého koeficientu
if (scanf("%lf", &koeficient) != 1) {
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", index);
return 0; // Zmenené z return 1 na return 0
return 0;
}
vysledok = koeficient;
index++;
// Čítanie ďalších koeficientov
while (scanf("%lf", &koeficient) == 1) {
while ((nacitane = scanf("%lf", &koeficient)) == 1) {
vysledok = vysledok * x + koeficient;
index++;
}
// Ak posledné čítanie zlyhalo a nebol to EOF, znamená to nečíselný vstup
if (!feof(stdin)) {
if (nacitane == 0) {
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", index);
return 0; // Zmenené z return 1 na return 0
return 0;
}
printf("Vysledok je: %.2f\n", vysledok);
return 0;
}
}