Upload files to "du2"
This commit is contained in:
parent
751df25501
commit
ab894763fd
36
du2/program.c
Normal file
36
du2/program.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
double x, koeficient, vysledok = 0;
|
||||
int index = 1;
|
||||
|
||||
// Nacitanie x
|
||||
if (scanf("%lf", &x) != 1) {
|
||||
printf("Chyba: Neplatná hodnota pre x.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
vysledok = koeficient;
|
||||
index++;
|
||||
|
||||
// Čítanie ďalších koeficientov
|
||||
while (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)) {
|
||||
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", index);
|
||||
return 0; // Zmenené z return 1 na return 0
|
||||
}
|
||||
|
||||
printf("Vysledok je: %.2f\n", vysledok);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user