Code:

using namespace std; # include <iostream> # include <string> # include <iomanip> # include <vector> double a; double b; double h; double f(double x) { return x* - 1; } double sign(double x) { if (x < 0) { return 0; } else { return 1; } } double FindRoot (double a,double b,double h) { double s; double x; s=sign(f(a)); while (s = sign(f(x))) { for (x=0; x < b; x=(a+b)/h) return x; } } double root=FindRoot (a, b, h); void PrintResults ( double a, double b, double root) { cout << "A root of the function f(x)=x^2-1 between " << a << " and " << b << " is " << root << endl << flush; } int main( ) { PrintResults (-2,0,0.01); return 0; }

*Last edited by shabbir; 27Apr2010 at 09:41.. Reason: Code blocks*