-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfp.cpp
72 lines (72 loc) · 1.34 KB
/
fp.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
double eq(double);
double val(double, double);
double mod(double);
double check(double, double, double);
int main(void)
{
double a,b,c,t;
cout << "Enter the value of a : ";
cin >> a;
cout << "Enter the value of b : ";
cin >> b;
int i=0;
do
{
c = val(a,b);
if(eq(a) != 0 && eq(b) != 0 && eq(c) != 0)
{
if(eq(a) * eq(c) < 0)
{
b=c;
}
else
{
a=c;
}
}
else
{
if(eq(a) == 0)
{
c=a;
break;
}
else if(eq(b) == 0)
{
c=b;
break;
}
else
{
break;
}
}
i++;
cout << setprecision(9) << c << endl;
} while(mod(eq(c)) > 0.001);
cout << "Root : " << setprecision(3) << c << endl;
cout << "Number of iterations : " << i << endl;
}
inline double eq(double x)
{
return ;
}
inline double val(double a, double b)
{
return (b - eq(b) * ( (b - a) / (eq(b) - eq(a)) ));
}
double mod(double x)
{
if(x < 0)
{
return -x;
}
else
{
return x;
}
}