# квадратное_уравнение

Apr 1st, 2024
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2.
3. using namespace std;
4.
5. double solver_square(double arr[], double x[]);
6.
7. void test_solver_square() {
8.     // a*x*x + b*x + c = 0
9.     double a = -1;
10.     double b = 3;
11.     double c = 4;
12.
13.     double arr[]{a,b,c};
14.     double sol[2];
15.
16.     double x;
17.     solver_square(arr, sol);
18.
19.     x = sol[0];
20.     cout << x << " : " << a * x * x + b * x + c << endl;
21.
22.     x = sol[1];
23.     cout << x << " : " << a * x * x + b * x + c << endl;
24.
25. }
26.
27. /// <summary>
28. /// Solve square equation
29. /// </summary>
30. /// <param name="arr">a, b, c</param>
31. /// <param name="x">solutions</param>
32. /// <returns></returns>
33. double solver_square(double arr[], double x[]) {
34.     double a = arr[0];
35.     double b = arr[1];
36.     double c = arr[2];
37.
38.     double d = b * b - 4 * a * c;
39.
40.     if (d >= 0) {
41.         x[0] = (-b - sqrt(d)) / (2 * a);
42.         x[1] = (-b + sqrt(d)) / (2 * a);
43.         return 0;
44.     }
45.     else
46.         return 1;
47. }
48.
49. int counter = 0;
50.
51. bool check_pin(int pin) {
52.     counter++;
53.     if (counter >= 3) {
54.         cout << "Unbloced pin" << endl;
55.         return false;
56.     }
57.
58.     return pin == 1234;
59. }
60.
61. void brutal_force() {
62.     srand(time(NULL));
63.     int pin;
64.
65.     while (true) {
66.         pin = rand() % 10000;
67.         if (check_pin(pin)) {
68.             cout << "The safe is opened." << endl;
69.             cout << "Pin: " << pin << endl;
70.             cout << "Count: " << counter << endl;
71.             break;
72.         }
73.     }
74. }
75.
76. const int n = 20;
77. char buff[n][n];
78.
79. void clear_buff() {
80.     for (int y = 0; y < n; y++) {
81.         for (int x = 0; x < n; x++) {
82.             buff[x][y] = ' ';
83.         }
84.     }
85. }
86.
87. void create_figure(int fig) {
88.     for (int y = 0; y < n; y++) {
89.         for (int x = 0; x < n; x++) {
90.             if ( -(y - n/2) == (x - n/2)  ||
91.                  (y - n / 2) == (x - n / 2))
92.                 buff[x][y] = '@';
93.         }
94.     }
95. }
96.
97. void show_figure() {
98.     for (int y = 0; y < n; y++) {
99.         for (int x = 0; x < n; x++) {
100.             cout << buff[x][y] << " ";
101.         }
102.         cout << endl;
103.     }
104. }
105.
106. int main() {
107.     //test_solver_square();
108.     //brutal_force();
109.     clear_buff();
110.     create_figure(1);
111.     show_figure();
112.
113.
114.     return 0;
115. }