Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- float func(float x){
- return (x*x)-(4*x)-10;
- }
- int main()
- {
- float a,b;
- //cin>>a>>b;
- scanf("%f%f",&a,&b);
- Step:
- float f1=func(a);
- float f2=func(b);
- float r=((f2*a)-(f1*b))/(f2-f1);
- //cout<<a<<" "<<b<<" "<<" "<<f1<<" "<<f2<<" ";
- printf("a: %.4f\tb: %.4f\tf1(a): %.4f\t\tf2(b):%.4f\t",a,b,f1,f2);
- if(abs((r-b)/r)>0.03){
- printf("Iterative is%.4f\n",r);
- a=b;
- f1=f2;
- b=r;
- f2=func(r);
- goto Step;
- }
- else printf("Root is: %.4f\n",r);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement