-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbypassM.cpp
More file actions
53 lines (42 loc) · 1.56 KB
/
bypassM.cpp
File metadata and controls
53 lines (42 loc) · 1.56 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
//TOPIC: Making life easy :)
#include <bits/stdc++.h>
using namespace std;
void functionCalculation(long double x, long double& a, long double& b, long double f[], int i) {
//this is the function part, if you need to change the function just change this part.
f[i] = pow(x, 3) - x - 1;
if (f[i] < 0) {
a = x;
} else if (f[i] > 0) {
b = x;
}
}
void calculationPart(long double x[], long double& a, long double& b, long double f[]) {
int i = 0;
do {
x[i] = (a + b) / 2;
functionCalculation(x[i], a, b, f, i);
i++;
} while (i < 2 || (i < 100 && abs(x[i-1] - x[i-2]) > 1e-9));
x[i] = (a + b) / 2;
}
int main() {
cout<<"To edit the function go to the function calculation part and change it , I am currently working on it ... ... ..."<<endl<<endl;
cout <<"Do the first part by your own and find the positive and negative sign\nput the negative at a, and put the positive at b: \n\n"<<endl<< "Negative value (a): ";
long double a, b;
cin >> a;
cout<<"Positive value (b): ";
cin>> b;
long double x[100] = {0};
long double f[100] = {0};
calculationPart(x, a, b, f);
// Set the precision to 9 digits
cout << fixed << setprecision(9);
for (int i = 0; i < 100 && x[i] != 0; ++i) {
cout << "x[" << i << "] = " << x[i] << endl;
cout << "f(x[" << i << "]) = " << f[i] << endl;
}
cout<<"Two value are same detected. PROCESS DONE."<<endl;
cout<<endl<<"IF the code is working well then don't mess with it...";
return 0;
}
//Diba_Dev(CSE 29B)