#include #include #include #define LINE_SIZE 100 int read_double(double *num){ char line[LINE_SIZE]; if(!fgets(line, LINE_SIZE, stdin)){ return 0; } char *endptr; *num = strtod(line, &endptr); if(endptr == line || (*endptr != '\0' && *endptr != '\n')){ return -1; } return 1; } int main(){ double x, coef, result = 0.0; int coef_index = 0; int read_status; if((read_status = read_double(&x)) != 1){ printf("Chyba: Nepodarilo sa nacitat hodnotu x.\n"); return 1; } while((read_status = read_double(&coef)) == 1){ if(coef_index == 0){ result = coef; }else{ result = result * x + coef; } coef_index++; } if(read_status == -1){ printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index); return 0; } if(coef_index == 0){ printf("Chyba: Nepodarilo sa nacitat ziadne koeficienty.\n"); return 1; } printf("Vysledok je: %.2f\n", result); return 0; }