include vcl include iostream include math include conio float float re

 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
#include <vcl.h>
#include <iostream.h>
#include <math.h>
#include <conio.h>
float f (float x)
{
return 3 * pow(x,4) - 8 * pow(x,3) - 18 * pow(x,2) + 2;
}
void dihot()
{
float a, b, eps, c;
cout << "a = ";
cin >> a;
cout << "b = ";
cin >> b;
cout << "eps = ";
cin >> eps;
if(f(a)* f(b) > 0)
cout << "Square nemae";
else
do
{
c = (a + b) / 2;
if (f(a)* f(c) < 0)
b = c;
else
a = c;
}while((b - a) / 2 > eps);
cout << "x = " << c;
}
void hord()
{
float a, b, eps, c, x0, xr;
cout << "a = ";
cin >> a;
cout << "b = ";
cin >> b;
cout << "eps = ";
cin >> eps;
if(f(a)* f(b) > 0)
cout << "Square nemae";
else
if(f(a) > 0)
x0 = b;
else
x0 = a;
do{
c = (a * f(b) - b * f(a)) / ( f(b) - f(a));
xr = fabs(x0 - c);
x0 = c;
if(f(a) * f(b) > 0)
a = c;
else
b = c;
} while(xr > eps);
cout << "x = " << c;
}
void main(){
cout << "--- METOD DIHOTOMII ---" << endl;
dihot();
cout << "\n--- METOD HORD ---" << endl;
hord();
getch();
}