-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrangingcat.cpp
More file actions
71 lines (64 loc) · 1.38 KB
/
Copy patharrangingcat.cpp
File metadata and controls
71 lines (64 loc) · 1.38 KB
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
//#include<bits/stdc++.h>
//using namespace std;
//
//int main()
//{
//
// int t; cin >> t;
// while (t--) {
// int n;
// cin >> n;
//
// string up, down;
// cin >> up >> down;
//
// int cn1 = 0, cn2 = 0, cn3;
// for (int i = 0; i < n; i++) {
// if (up[i] == '0' && down[i] == '1')
// cn1++;
// else if (up[i] == '1' && down[i] == '0')
// cn2++;
// }
//
// cn3 = min(cn1, cn2);
// cn1 -= cn3;
// cn2 -= cn3;
//
// cout << cn1 + cn2 + cn3 << endl;
// }
//
//}
#include <bits/stdc++.h>
using namespace std;
double f(double x)
{
return x * x - 4*x - 10 ;
}
double secantMethod(double x1, double x2)
{
double x3;
int i=1 ;
do
{
x3 = x2 - ((f(x2) * (x2 - x1)) / (f(x2) - f(x1)));
if (abs(x3 - x2) <= 0.001)
return x3;
x1 = x2;
x2 = x3;
i++ ;
}
while (1);
}
int main()
{
double x1, x2, epsilon;
cout<<setw(10)<<"Using Secent Method : \n" ;
cout<< "\tThe Equation is = x^2 -4^x -10 = 0 \n";
cout << "Enter first initial guess (x1): ";
cin >> x1;
cout << "Enter second initial guess (x2): ";
cin >> x2;
double root = secantMethod(x1, x2);
cout << "\n\tRoot of the equation: " << root << endl;
return 0;
}