refresh
This commit is contained in:
parent
7379ce8f0e
commit
255f0ac94e
@ -4,7 +4,7 @@
|
||||
|
||||
int read_number (double *num) {
|
||||
char buffer[50];
|
||||
if (!fgets(buffer, sizeof(buffer), stdin)) { //если fgets не смог считать строку
|
||||
if (!fgetc(buffer, sizeof(buffer), stdin)) { //если fgets не смог считать строку
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ int read_number (double *num) {
|
||||
double hornerovaschema (double x, double cofecients[], int count) { //вычесляет значение многочлена в точке x
|
||||
double result = 0.0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
result = result * x + coefficients[i];
|
||||
result = result * x + cofecients[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -25,7 +25,7 @@ double hornerovaschema (double x, double cofecients[], int count) { //вычес
|
||||
int main() {
|
||||
double x;
|
||||
double cof[maxcoe];
|
||||
double count = 0;
|
||||
int count = 0;
|
||||
|
||||
printf("Zadajte x: ");
|
||||
if (!read_number(&x)) { //если не может считать
|
||||
@ -35,7 +35,7 @@ int main() {
|
||||
|
||||
printf("Zadajte koeficienty (po jednom na riadok, ukoncite prazdnym riadkom):\n");
|
||||
|
||||
while (count < maxcoe)
|
||||
while (count < maxcoe) {
|
||||
double coef; //переменна для хранения считанного коэффициента
|
||||
char buffer[50];//строковый буфер для fgetc
|
||||
|
||||
@ -43,12 +43,17 @@ int main() {
|
||||
break;
|
||||
}
|
||||
|
||||
if (sscanf(buffer, sizeof(buffer), stdin)) {
|
||||
if (sscanf(buffer, "%lf", &coef) != 1) {
|
||||
printf("Chyba. Nepodarilo sa nacitat koeficient %d.\n", count + 1);
|
||||
return 1
|
||||
return 1;
|
||||
}
|
||||
cof[count] = coef;
|
||||
count++;
|
||||
}
|
||||
|
||||
double result = hornerovaschema(x, cof, count);
|
||||
|
||||
printf("%.2f\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user