Iterative

 // Iterative Method


#include<iostream>

#include<math.h>

#define err 0.0001

using namespace std;

float iterative(float x)

{

    return //write your equation in form of x

}


float f(float x)

{

    return //Write your equation

}


int main()

{

    int i = 1;

    float x0,x1;

    cout<<"Enter the first approximation: ";

    cin>>x0;

    x1= iterative(x0);

    cout<<"Iteration\t\tRoot\n";


    while(fabs(x1-x0)>err)

    { 

        cout<<"X"<<i<<"\t"<<x1<<endl;

        x0 = x1;

        x1 = iterative(x0);

        i++;

    }


    cout<<"Root after "<<i<<" iteration = "<<x1;

    return 0;

}


0 Comments: