Secant Method

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define F(x) x*x+x-2
int main (void)
{
   float x1,x2,x3,x,e=1.0,c=0,a=0,fx1,fx2;
   clrscr();
   printf("Enter the value of x1 and x2: ");
   scanf("%f %f",&x1,&x2);
   while(e>=0.000001)
   {
      x=x1;
      fx1=F(x);
      x=x2;
      fx2=F(x);
      x3=x2-(fx2*(x2-x1)/(fx2-fx1));
      a=x3;
      e=fabs((x3-x2)/x3);
      x1=x2;
      x2=x3;
      c++;
   }
	printf("Itteration no: %.0f\nAns: %f",c,a);
   getch();
   return 0;
}

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *