-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbisect.cpp
More file actions
60 lines (44 loc) · 805 Bytes
/
Copy pathbisect.cpp
File metadata and controls
60 lines (44 loc) · 805 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
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
using namespace std;
int n;
float arr[20];
float horner(int i, float w,float u){
u = w * u;
if(i == n){
return arr[i] + u;
}
return horner(i+1,w,arr[i] + u);
}
int main(){
int w;
float a;
float b;
cout << "podaj st. W(x)" << endl;
cin >> n;
for(int i = 0; i < n+1; i++){
cout << "podaj " << i + 1 << " wspolczynnik" << endl;
cin >> arr[i];
}
float d = 0.001;
float fa = 1;
float fb = 1;
while(fa * fb > 0){
cout << "podaj a i b" << endl;
cin >> a;
cin >> b;
fa = horner(0,a,0);
fb = horner(0,b,0);
}
float valX = (b+a)/2;
float fMid = horner(0,valX,0);
while(abs(fMid) > d){
valX = (b+a)/2;
fMid = horner(0,valX,0);
if(fa * fMid < 0){
b = valX;
} else {
a = valX;
}
}
cout << "miejsce zerowe to: " << valX;
}