You are on page 1of 2

/*To find roots of given equation*/ #include<iostream.h> #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<iomanip.h> #include<math.

h> float ffx(float ); float fdx(float ); void main(void) { clrscr(); int i,n; float x[20]; cout<<"\n"<<" NEWTON RAPHSON METHOD "<<"\n"; cout<<"\n"<<"Enter The initial value of X "<<"\n"; cin>>x[0]; cout<<"\n"<<"Enter the number of Iteration to be performed"<<"\n"; cin>>n; cout<<"\n\n"; cout<<"The number of Iteration and value of X "; for(i=0;i<=n;i++) { x[i+1] = x[i] - ffx(x[i])/fdx(x[i]) ; cout<<"\n\n"<<setw(4)<<i<<setw(10)<<x[i]; } cout<<"\n\n"; cout<<"The value of X atfer "<<n<<" Iteration is = "; cout<<x[n]; getch(); } float ffx(float x) { float fx; fx = x*x - 2*x -2; return (fx); } float fdx(float x) { float fd; fd = 2*x -2 ; return(fd); }

You might also like