All pastes #972665 Raw Edit

Miscellany

public cpp v1 · immutable
·published 2008-04-05 17:04 UTC
rendered paste body
#include <iostream>using namespace std;#include <math.h>double F(double x){        double res = pow(x, 9) - pow(x, 7) + 2 * pow(x, 2) -1;        return res;}void print_roots(){                double low, high;        cout<<"low=";        cin>>low;        cout<<"high=";        cin>>high;        for(int i = 0; i < 1000 ; ++i){                double mid = (float)(low + high)/2;                double val = F(mid);                cout << mid << ":" << val << endl;                if(val < 0.00001 && val > -0.00001){                        cout << "Root is " << mid << endl;                        return;                }                else if (val < 0 )                        low = mid;                else                        high = mid;        }}int main(int argc, char **argv){        print_roots();        system("pause");        return 0;}