I want to calculate secant method using C language
That is a program---->
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
main()
{
double fx(double x);
double x0,x1,x2,f0,f1,f2,err;
int n,i;
printf("\n\n f(x) =x*x*x-5x-7");
printf("\n\nEnter an interval [x0,x1] in"
" which root is to be found");
printf("\nx0 =");
scanf("%f",&x0); / INTERVAL[x0,x1] is to be entered here */
printf("x1=");
scanf("%f",&x1);
printf("\n Enter the number of iterations=");
scanf("%d",&n);
printf("\npress any key for display of iterations...\n");
getchar();
i=0;
while (n > 0)
{
f0=fx(x0);
f1=fx(x1);
x2 = x1-((x1-x0)/(f1-f0))f1;
i++;
printf("\n x[%d]=%f x[%d]=%f",i,i-1,x0,i,x1);
printf("\n f[%d]=%f f[%d]=%f",i,i-1,f0,i,f1);
printf("\n x[%d]=%f",i+1,x2);
x0=x1;
x1=x2;
getchar();
}
printf("\n\nThe value of root is =%f",x2);
}
double fx(double x)
{
double f;
f=x*x*x-5x-7;
return(f);
}
But while running not the erreo is displayed but the results displayed is
f(x) =x*x*x-5*x-7
Enter an interval [x0,x1] in which root is to be found
x0 =2.5
x1=3
Enter the number of iterations=4
press any key for display of iterations...
x[1]=0.000000 x[0]=0.000000
f[1]=-7.000000 f[0]=-7.000000
x[2]=inf
Means not able to calculate root as seen in the output it is x[1]=0...
so what will be the problem????