diff --git a/.gitignore b/.gitignore index e624d96..1000347 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -.out +a.out .ccls .ccls-cache diff --git a/alg_4_1.cpp b/alg_4_1.cpp index b6bad89..c4f07cb 100644 --- a/alg_4_1.cpp +++ b/alg_4_1.cpp @@ -1,5 +1,4 @@ #include -using namespace std; int gcd_recur(int n1, int n2) { @@ -20,8 +19,11 @@ int gcd_recur(int n1, int n2) int main() { + setlocale(LC_ALL, "Russian"); int a, b; - cin >> a >> b; - cout << gcd_recur(a, b); -} \ No newline at end of file + std::cout << "Введите два числа для определения НОД: "; + std::cin >> a >> b; + + std::cout << "НОД: " << gcd_recur(a, b) << std::endl; +} diff --git a/alg_4_2.cpp b/alg_4_2.cpp index 4b2f7c5..3fa816e 100644 --- a/alg_4_2.cpp +++ b/alg_4_2.cpp @@ -1,5 +1,4 @@ #include -using namespace std; int fib(int n) { @@ -11,7 +10,11 @@ int fib(int n) int main() { - int n; cin >> n; + setlocale(LC_ALL, "Russian"); + int n; - cout << fib(n); -} \ No newline at end of file + std::cout << "Введите число n для определения числа Фибоначчи: "; + std::cin >> n; + + std::cout << fib(n) << std::endl; +} diff --git a/alg_4_3.cpp b/alg_4_3.cpp index c20addc..d3b42a4 100644 --- a/alg_4_3.cpp +++ b/alg_4_3.cpp @@ -1,55 +1,57 @@ #include -using namespace std; +#include double root(int n) { - double L, R, B; - L = 0; R = n; + double L, R, B; + L = 0; R = n; - while (fabs(R - L) > 0.00001) + while (std::fabs(R - L) > 0.00001) + { + B = (L + R) / 2; + + if ( B*B > n) { - B = (L + R) / 2; - - if ( B*B > n) - { - R = B; - } - else { - L = B; - } + R = B; } - return B; + else { + L = B; + } + } + return B; } double root_hf_div(double n, double L, double R) { - double B; + double B; - if (fabs(R - L) < 0.00001) - { - return (L + R) / 2; - } - else - { - B = (L + R) / 2; + if (std::fabs(R - L) < 0.00001) + { + return (L + R) / 2; + } + else + { + B = (L + R) / 2; - if ((B * B) > n) - { - return root_hf_div(n, L, B); - } - else - { - return root_hf_div(n, B, R); - } - } + if ((B * B) > n) + { + return root_hf_div(n, L, B); + } + else + { + return root_hf_div(n, B, R); + } + } } int main() { - setlocale(LC_ALL, "Russian"); - double n; cin >> n; + setlocale(LC_ALL, "Russian"); + double n; - cout << "Обычный: " << root(n) << endl; - - cout << "Рекурсивный: " << root_hf_div(n, 1, n) << endl; -} \ No newline at end of file + std::cout << "Введите число n для определения корня: "; + std::cin >> n; + + std::cout << "Обычный: " << root(n) << std::endl; + std::cout << "Рекурсивный: " << root_hf_div(n, 1, n) << std::endl; +} diff --git a/alg_4_4.cpp b/alg_4_4.cpp index 3507c63..22c3c41 100644 --- a/alg_4_4.cpp +++ b/alg_4_4.cpp @@ -1,5 +1,4 @@ #include -using namespace std; int f(int n, int sum) { @@ -12,7 +11,11 @@ int f(int n, int sum) int main() { - int n; cin >> n; + setlocale(LC_ALL, "Russian"); + int n; - cout << f(n, 0); -} \ No newline at end of file + std::cout << "Введите число n для определения суммы его цифр: "; + std::cin >> n; + + std::cout << "Сумма: " << f(n, 0); +} diff --git a/alg_4_5.cpp b/alg_4_5.cpp index f3e65ed..34c57f8 100644 --- a/alg_4_5.cpp +++ b/alg_4_5.cpp @@ -1,5 +1,4 @@ #include -using namespace std; int f(int n) { @@ -10,6 +9,11 @@ int f(int n) int main() { - int n; cin >> n; - cout << f(n); -} \ No newline at end of file + setlocale(LC_ALL, "Russian"); + int n; + + std::cout << "Введите число n для определения значения функции Дейкстры: "; + std::cin >> n; + + std::cout << "Значение функции Дейкстры: " << f(n) << std::endl; +} diff --git a/alg_4_6.cpp b/alg_4_6.cpp index ed68bde..f327e3f 100644 --- a/alg_4_6.cpp +++ b/alg_4_6.cpp @@ -1,26 +1,26 @@ #include -using namespace std; void move(int a, int b, int c, int n) { - if (n == 1) - { - cout << "from " << a << " to " << c << endl; - } - else - { - move(a, c, b, n - 1); - - cout << "from " << a << " to " << c << endl; - - move(b, a, c, n - 1); - } + if (n == 1) + { + std::cout << "Из " << a << " в " << c << std::endl; + } + else + { + move(a, c, b, n - 1); + std::cout << "Из " << a << " в " << c << std::endl; + move(b, a, c, n - 1); + } } int main() { - int n; - cout << "Enter the amount of disks: "; cin >> n; + setlocale(LC_ALL, "Russian"); + int n; + + std::cout << "Количество дисков: "; + std::cin >> n; - move(1, 2, 3, n); -} \ No newline at end of file + move(1, 2, 3, n); +}