Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- double Func(double x) {
- //Здесь должны написать функцию, которую она дала...
- //Я напишу просто возврат значения х
- return x;
- }
- int main()
- {
- double y, eps;
- int n;
- double x1, x2, xt;
- cout << "Enter y:";
- cin >> y;
- cout << endl;
- cout << "Enter eps:";
- cin >> eps;
- cout << endl;
- cout << "Enter n:";
- cin >> n;
- cout << endl;
- system("cls");
- x1 = 1;
- while (Func(x1) > y) {
- x1 /= 2;//x1=x1/2; одно и то же
- };
- x2 = 1;
- while (Func(x2) < y) {
- x2 *= 2;//x2=x2*2
- };
- while ((x2 - x1) > eps) {
- xt = (x1 + x2) / 2;
- if (Func(xt) > y) {
- x2 = xt;
- }
- else {
- x1 = xt;
- };
- };
- cout << "xt=" << xt << endl;
- cout << "y=" << y<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement