-
Notifications
You must be signed in to change notification settings - Fork 0
/
8.11.cpp
47 lines (41 loc) · 1.14 KB
/
8.11.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
#include "tasks.h"
struct equasion {
int a;
int b;
int c;
};
struct roots {
double r1;
double r2;
};
roots solve(equasion eq) {
roots r;
double d = (pow(eq.b,2) - 4 * eq.a * eq.c);
if (d < 0) {
cout << "Ðåøåíèé â ðàöèîíàëüíûõ ÷èñëàõ íå ñóùåñòâóåò" << endl;
r.r1 = NULL;
r.r2 = NULL;
cout << "------------------------------" << endl << endl;
return r;
}
r.r1 = (-1*eq.b + sqrt(d)) / (2*eq.a);
r.r2 = (-1*eq.b - sqrt(d)) / (2*eq.a);
return r;
}
void main_811() {
equasion eq;
const char* path = "8.11_in.txt";
int* file = read_f_int(path);
for (int i = 0; i < 18; i = i + 3) {
eq.a = file[i];
eq.b = file[i+1];
eq.c = file[i+2];
cout << "------------------------------" << endl;
cout << "Óðàâíåíèå: " << eq.a << "x^2 + " << eq.b << "x + " << eq.c << " = 0" << endl;
roots r = solve(eq);
if ((r.r1 != NULL) and (r.r2 != NULL)) {
cout << "Ðåøåíèÿ: " << endl << "x1: " << r.r1 << endl << "x2: " << r.r2 << endl;
cout << "------------------------------" << endl << endl;
}
}
}