-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecant Method.c
More file actions
46 lines (39 loc) · 811 Bytes
/
Secant Method.c
File metadata and controls
46 lines (39 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
//Secant Method
float f(float x)
{
return (pow(x,2)-10);
}
int main()
{
float a,b;
printf("This is not a bracketing algorithm\n");
printf("enter the value of the a\n");
scanf("%f",&a);
printf("enter the value of the b\n");
scanf("%f",&b);
int n,i;
printf("enter the maximum no of iterations \n");
scanf("%d",&n);
float tol;
printf("enter the tolerance limit \n");
scanf("%f",&tol);
for(i=0;i<=n;i++)
{
float m=b-f(b)*(b-a)/(f(b)-f(a));
if(fabs(f(m))<tol)
{
printf("#########\nANSWER\n");
printf("m is %f and value is %f",m,f(m));
exit(0);
}
else
{ a=b;
b=m;
}
printf("%f \t%f\n",m,f(m));
}
return 0;
}