#include<iostream.h>
#include<conio.h>
#include<math.h>
#define f(x) (x*x - 4*x - 10)
#define g(x) (2*x - 4)
#define e 0.05
int main()
{
float x0, x1, f1, f2, E;
static int count=0;
cout << "Enter Xo: " ;
cin >> x0 ;
cout << endl << "Estimated error: " << e << endl;
Top:
f1 = f(x0);
f2 = g(x0);
x1 = x0 - (f1 / f2);
E = ((fabs((x1 - x0) / x1)) * 100);
if(E < e){
cout << endl <<"Error: " << E << " %" << endl;
cout << endl <<"The root is " << x1 << endl;
cout << endl <<"Number of iterations: " << count;
}
else{
count ++;
x0 = x1;
goto Top;
}
getch();
return 0;
}
No comments:
Post a Comment
If you have any problem, please leave your message here.