2025-03-06 10:21:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2025-03-06 10:40:23 +00:00
|
|
|
#include <ctype.h>
|
2025-03-06 10:21:11 +00:00
|
|
|
|
|
|
|
#define LINE_SIZE 100
|
|
|
|
|
2025-03-06 10:40:23 +00:00
|
|
|
int read_double(double *value) {
|
|
|
|
char line[LINE_SIZE];
|
|
|
|
if (fgets(line, LINE_SIZE, stdin) == NULL) {
|
|
|
|
return 0; // Chyba pri čítaní
|
|
|
|
}
|
|
|
|
char *endptr;
|
|
|
|
*value = strtod(line, &endptr);
|
|
|
|
if (endptr == line || (*endptr != '\0' && *endptr != '\n')) {
|
|
|
|
return 0; // Neplatný vstup
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2025-03-06 10:21:11 +00:00
|
|
|
int main() {
|
2025-03-06 10:40:23 +00:00
|
|
|
double x;
|
|
|
|
if (!read_double(&x)) {
|
|
|
|
printf("Chyba: Nepodarilo sa načítať hodnotu x.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
double coef;
|
|
|
|
double result = 0;
|
|
|
|
int coef_count = 0;
|
2025-03-06 10:21:11 +00:00
|
|
|
|
2025-03-06 10:40:23 +00:00
|
|
|
while (1) {
|
|
|
|
if (!read_double(&coef)) {
|
|
|
|
if (coef_count == 0) {
|
|
|
|
printf("Chyba: Neboli zadané žiadne koeficienty.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
2025-03-06 10:36:49 +00:00
|
|
|
}
|
2025-03-06 10:40:23 +00:00
|
|
|
result = result * x + coef;
|
|
|
|
coef_count++;
|
2025-03-06 10:21:11 +00:00
|
|
|
}
|
2025-03-06 10:40:23 +00:00
|
|
|
|
|
|
|
printf("Vysledok je: %.2f\n", result);
|
2025-03-06 10:21:11 +00:00
|
|
|
return 0;
|
2025-03-06 10:40:23 +00:00
|
|
|
}
|