diff --git a/program b/program new file mode 100755 index 0000000..bfbf30f Binary files /dev/null and b/program differ diff --git a/program.c b/program.c new file mode 100644 index 0000000..f283962 --- /dev/null +++ b/program.c @@ -0,0 +1,38 @@ +#include + +#define MAX_COEFFS 256 + +int main() { + double x; + double coeffs[MAX_COEFFS]; + int n = 0; + char line[256]; + + if (fgets(line, sizeof(line), stdin) == NULL || sscanf(line, "%lf", &x) != 1) { + fprintf(stderr, "Chyba: nepodarilo sa nacitat hodnotu x.\n"); + return 1; + } + + while (fgets(line, sizeof(line), stdin) != NULL) { + if (line[0] == '\n' || line[0] == '\r') break; + + if (sscanf(line, "%lf", &coeffs[n]) != 1) { + fprintf(stderr, "Chyba: nepodarilo sa nacitat koeficient a[%d].\n", n); + return 1; + } + n++; + } + + if (n == 0) { + fprintf(stderr, "Chyba: nepodarilo sa nacitat koeficient a[0].\n"); + return 1; + } + + double result = 0.0; + for (int i = 0; i < n; i++) { + result = result * x + coeffs[i]; + } + + printf("Vysledok je: %.2f\n", result); + return 0; +}