Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <iomanip>
- #include <conio.h>
- using namespace std;
- double f1(double c)
- {
- double z = pow(c, 3.0) - c - 1;
- return z;
- }
- double f2(double k) {
- double g = 3 * (pow(k, 2.0)) - 1;
- return g;
- }
- int main()
- {
- int n = 0;
- long double b = 1.5, a = -1.5, c, E = 0.001,x;
- while (b - a > E) {
- n++;
- c = (a + b) / 2;
- if (f1(b) * f1(c) < 0)
- a = c;
- else
- b = c;
- }
- x = (a + b) / 2;
- cout << "x=" << x << endl;
- cout << "n=" << n << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment