Search:

Submit Article

# SECANT METHOD

Posted By: Abe Fischer     Category: C Programming     Views: 63922

## Code for SECANT METHOD in C Programming

```#include<stdio.h>
#include<conio.h>
#include<math.h>
#define ESP 0.0001
#define F(x) (x)*(x) - 4*(x) - 10
void main()
{
float x1,x2,x3,f1,f2,t;
clrscr();
printf("\nEnter the value of x1: ");
scanf("%f",&x1);
printf("\nEnter the value of x2: ");
scanf("%f",&x2);
printf("\n______________________________________________\n");
printf("\n    x1\t  x2\t  x3\t     f(x1)\t f(x2)");
printf("\n______________________________________________\n");
do
{
f1=F(x1);
f2=F(x2);
x3=x2-((f2*(x2-x1))/(f2-f1));
printf("\n%f   %f   %f   %f   %f",x1,x2,x3,f1,f2);
x1=x2;
x2=x3;
if(f2<0)
t=fabs(f2);
else
t=f2;
}while(t>ESP);
printf("\n______________________________________________\n");
printf("\n\nApp.root = %f",x3);
getch();
}

/* OUT PUT---------Enter the value of x1: 4Enter the value of x2: 2___________________________________________________________    x1        x2         x3         f(x1)       f(x2)___________________________________________________________4.000000   2.000000   9.000000   -10.000000   -14.0000002.000000   9.000000   4.000000   -14.000000    35.0000009.000000   4.000000   5.111111    35.000000   -10.0000004.000000   5.111111   5.956522   -10.000000   -4.3209875.111111   5.956522   5.722488   -4.320987     1.6540635.956522   5.722488   5.741121    1.654063    -0.1430845.722488   5.741121   5.741659   -0.143084    -0.0040155.741121   5.741659   5.741657   -0.004015     0.000010___________________________________________________________App.root = 5.741657*/```
Share:

Didn't find what you were looking for? Find more on SECANT METHOD Or get search suggestion and latest updates.

 Abe Fischer author of SECANT METHOD is from Frankfurt, Germany. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!