C program to implement secant method to find the root of equation

//program to implement secant method to find the root of equation
//f(x)=0
#include<stdio.h>
#include<conio.h>
#include<math.h>
double f(double x)
{
return(cos(x)-x*exp(x));
}

void main()
{
float x0,x1,x2,del;
int i,n;
clrscr();
printf("\n Enter the value of x0,x1 ");
scanf("%f %f",&x0,&x1);
printf("\n Enter the value of delta : ");
scanf("%f",&del);
printf("\n Enter The number of Itreation : ");
scanf("%d",&n);
if(fabs(f(x0)-f(x1))<del)
{
printf("\n Initial approximation are too small!!");
}
else
{
for(i=1;i<=n;i++)
{
x2=(x1*f(x0)-x0*f(x1))/(f(x0)-f(x1));
x0=x1;
x1=x2;
printf("\n\n\t %dth Approximate root is : %f ",i,x2);
}
}
getch();
}

Comments

Popular Posts