Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define eps .001
- using namespace std;
- int main()
- {
- double a,b,c,x0,x;
- double r=1;
- cout <<"Enter the value of a,b,c : ";
- cin >> a >>b >>c;
- if(a>0)
- {
- cout <<"Enter the value of x0(initial guess) :";
- cin >> x0;
- x=x0;
- while(1)
- {
- double fx = a*x*x +b*x +c;
- double fpx = 2*a*x +b;
- x = x-(fx/fpx);
- cout <<"iteration "<<r++<<" root is : "<<x<<endl;
- //break;
- }
- cout<<"The Root is : " <<x<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment