Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- #define e 0.00001
- float func(float x){
- return (x*x*x-2*x-5);
- }
- int main(){
- int i =0;
- float x1,x2,x3,fx1,fx2,fx3;
- printf("Enter You Guess for x1 and x2 \n");
- scanf("%f%f",&x1,&x2);
- do{
- fx1 = func(x1);
- fx2 = func(x2);
- x3 = ((x1*fx2)-(x2*fx1))/(fx2-fx1);
- fx3 = func(x3);
- if (i==0){
- printf("x1 x2 x3 f(x1) f(x2) f(x3) \n ");
- }
- printf("%f %f %f %f %f %f \n",x1,x2,x3,fx1,fx2,fx3);
- x1=x2;
- x2=x3;
- ++i;
- }while ((fabs(fx3))>e);
- printf("The Root Using Second Method %f \n",x3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement