Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- #define t 0.0001
- #define F(x) x*x*x-5*x+3
- int main(){
- float x0,x1,x2,f0,f1,f2;
- printf("Enter the value of x0: ");
- scanf("%f",&x0);
- printf("Enter the value of x1: ");
- scanf("%f",&x1);
- printf("\n_______________________________________________");
- printf("\nx0\t x1\t x2\t f0\t f1\t f2 ");
- printf("\n_______________________________________________");
- do{
- f0=F(x0);
- f1=F(x1);
- x2=x0-((f0*(x1-x0))/(f1-f0));
- f2=F(x2);
- printf("\n%f %f %f %f %f",x0,x1,x2,f1,f2);
- if(F(x0)*F(x2)<0){
- x1=x2;
- }
- else{
- x0=x2;
- }
- }while(fabs(f2)>t||F(x2)==0);
- printf("\n___________________________________________");
- printf("\n\nApproaximation root:%f",x2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement