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