#include <iostream>
#include <math.h>
double f(double t)
{
return t - 2;
}
int main()
{
int N = 10000;
double a, b, fa,fb,fc,c;
a = 0.;
b = 3.14;
for (int i = 1; i < N; i++) {
fa = f(a);
fb = f(b);
c = (a + b) / 2;
fc = f(c);
if (fa * fb > 0) { std::cout << "wrong!"; break; }
if (fc * fb > 0) b = c; else a = c;
}
std::cout << "Solution =" << c << "\n";
return 0;
}
No comments:
Post a Comment