#include #include #define maxcoe 100 int read_number (double *num) { char buffer[50]; if (!fgets(buffer, sizeof(buffer), stdin)) { //если fgets не смог считать строку return 0; } if (sscanf(buffer, "%lf", num) != 1) { //переделываем в double. Если всё успешно return 0; } return 1; } double hornerovaschema (double x, double cofecients[], int count) { //вычесляет значение многочлена в точке x double result = 0.0; for (int i = 0; i < count; i++) { result = result * x + cofecients[i]; } return result; } int main() { double x; double cof[maxcoe]; int count = 0; if (!read_number(&x)) { //если не может считать printf("Nepodarilo sa nacitat zaklad x\n"); return 0; } while (count < maxcoe) { double coef; //переменна для хранения считанного коэффициента char buffer[50];//строковый буфер для fgetc if (!fgets(buffer, sizeof(buffer), stdin) || buffer[0] == '\n') { break; } if (sscanf(buffer, "%lf", &coef) != 1) { printf("Nepodarilo sa nacitat polynom na %d mieste.\n", count + 1); return 0; } cof[count] = coef; count++; } double result = hornerovaschema(x, cof, count); printf("Vysledok je: %.2f\n", result); return 0; }