Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "Russian");
- int n = 0;
- double y0 = 1, x = 0, eps = 0, y;
- bool isIncorrect;
- cout << "Пожалуйста, введите число EPS (EPS > 0): " << endl;
- do {
- cin >> eps;
- isIncorrect = false;
- if (cin.fail())
- {
- cout << "Пожалуйста, введите число. " << endl;
- isIncorrect = true;
- cin.clear();
- while (cin.get() != '\n');
- }
- if (!isIncorrect and (eps <= 0))
- {
- cout << "Число Эпсилон должно быть положительным." << endl;
- cin.clear();
- }
- } while (isIncorrect);
- cout << "Введите x: " << endl;
- do {
- isIncorrect = false;
- cin >> x;
- if (cin.fail()) {
- cout << "Пожалуйста, введите число. " << endl;
- isIncorrect = true;
- cin.clear();
- while (cin.get() != '\n');
- }
- } while (isIncorrect);
- do {
- y = y0;
- y0 = 0.5 * (y + (x / y));
- n++;
- } while (abs(y - y0) >= eps);
- cout << "Корень из x = " << y0 << endl << "Количество итераций: " << n;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement