Advertisement
Istanvir389

False Position

May 5th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #define t 0.0001
  4. #define F(x) x*x*x-5*x+3
  5. int main(){
  6.     float x0,x1,x2,f0,f1,f2;
  7.     printf("Enter the value of x0: ");
  8.     scanf("%f",&x0);
  9.     printf("Enter the value of x1: ");
  10.     scanf("%f",&x1);
  11.     printf("\n_______________________________________________");
  12.     printf("\nx0\t x1\t x2\t f0\t f1\t f2  ");
  13.     printf("\n_______________________________________________");
  14.     do{
  15.         f0=F(x0);
  16.         f1=F(x1);
  17.         x2=x0-((f0*(x1-x0))/(f1-f0));
  18.         f2=F(x2);
  19.         printf("\n%f %f %f %f %f",x0,x1,x2,f1,f2);
  20.         if(F(x0)*F(x2)<0){
  21.             x1=x2;
  22.         }
  23.         else{
  24.             x0=x2;
  25.         }
  26.         }while(fabs(f2)>t||F(x2)==0);
  27.         printf("\n___________________________________________");
  28.         printf("\n\nApproaximation root:%f",x2);
  29.  
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement