Professional Documents
Culture Documents
h> // for clear screen float f(float x); float f1(float x); void newton(float *x,float x0,int*itr); //mathematics funs int main() { int itr=0, maxitr; float x, x0, aerr,e; clrscr(); cout<<"enter the value of x0, allowed error and maximum iteration\n"; cin>>x0>>aerr>>maxitr; do { newton(&x,x0,&itr); e=fabs((x0-x)/x)*100; //for absolute error cout<<"error in this iteration="<<e<<"%"<<"\n"; x0=x; } while(itr<maxitr&&e>aerr); getch(); return 0; } float f(float x) { return (sin(x)+x-3); // fncs to find root } float f1(float x) { return(sin(x)+1); } void newton(float *x, float x0,int*itr) { *x=x0-(f(x0)/f1(x0)); ++(*itr);