C : secant method


#include<stdio.h>
#include<conio.h>
#include<math.h>
#define E 0.00001
#define f(x) x*x-4*x-10
int main()
{
float x1,x2,x3,f1,f2;
printf("Enter two value (x1,x2) : ");
scanf("%f",&x1);
scanf("%f",&x2);
f1=f(x1);
f2=f(x2);
Label:
x3=(f2*x1-f1*x2)/(f2-f1);
if(fabs((x3-x2)/x3)>E)
{
x1=x2;
f1=f2;
x2=x3;
f2=f(x3);
goto Label;
}
else
printf("The root is %f",x3);
getch();
return(0);
}

No comments:

Post a Comment