Fixed my old formatting and patched things that were left as-is due to burnout and laziness
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,3 @@
|
|||||||
.out
|
a.out
|
||||||
.ccls
|
.ccls
|
||||||
.ccls-cache
|
.ccls-cache
|
||||||
|
|||||||
10
alg_4_1.cpp
10
alg_4_1.cpp
@@ -1,5 +1,4 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int gcd_recur(int n1, int n2)
|
int gcd_recur(int n1, int n2)
|
||||||
{
|
{
|
||||||
@@ -20,8 +19,11 @@ int gcd_recur(int n1, int n2)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
setlocale(LC_ALL, "Russian");
|
||||||
int a, b;
|
int a, b;
|
||||||
cin >> a >> b;
|
|
||||||
|
|
||||||
cout << gcd_recur(a, b);
|
std::cout << "Введите два числа для определения НОД: ";
|
||||||
}
|
std::cin >> a >> b;
|
||||||
|
|
||||||
|
std::cout << "НОД: " << gcd_recur(a, b) << std::endl;
|
||||||
|
}
|
||||||
|
|||||||
11
alg_4_2.cpp
11
alg_4_2.cpp
@@ -1,5 +1,4 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int fib(int n)
|
int fib(int n)
|
||||||
{
|
{
|
||||||
@@ -11,7 +10,11 @@ int fib(int n)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int n; cin >> n;
|
setlocale(LC_ALL, "Russian");
|
||||||
|
int n;
|
||||||
|
|
||||||
cout << fib(n);
|
std::cout << "Введите число n для определения числа Фибоначчи: ";
|
||||||
}
|
std::cin >> n;
|
||||||
|
|
||||||
|
std::cout << fib(n) << std::endl;
|
||||||
|
}
|
||||||
|
|||||||
76
alg_4_3.cpp
76
alg_4_3.cpp
@@ -1,55 +1,57 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
#include <cmath>
|
||||||
|
|
||||||
double root(int n)
|
double root(int n)
|
||||||
{
|
{
|
||||||
double L, R, B;
|
double L, R, B;
|
||||||
L = 0; R = n;
|
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;
|
R = B;
|
||||||
|
|
||||||
if ( B*B > n)
|
|
||||||
{
|
|
||||||
R = B;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
L = B;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return B;
|
else {
|
||||||
|
L = B;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return B;
|
||||||
}
|
}
|
||||||
|
|
||||||
double root_hf_div(double n, double L, double R)
|
double root_hf_div(double n, double L, double R)
|
||||||
{
|
{
|
||||||
double B;
|
double B;
|
||||||
|
|
||||||
if (fabs(R - L) < 0.00001)
|
if (std::fabs(R - L) < 0.00001)
|
||||||
{
|
{
|
||||||
return (L + R) / 2;
|
return (L + R) / 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
B = (L + R) / 2;
|
B = (L + R) / 2;
|
||||||
|
|
||||||
if ((B * B) > n)
|
if ((B * B) > n)
|
||||||
{
|
{
|
||||||
return root_hf_div(n, L, B);
|
return root_hf_div(n, L, B);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return root_hf_div(n, B, R);
|
return root_hf_div(n, B, R);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
setlocale(LC_ALL, "Russian");
|
setlocale(LC_ALL, "Russian");
|
||||||
double n; cin >> n;
|
double n;
|
||||||
|
|
||||||
cout << "Обычный: " << root(n) << endl;
|
std::cout << "Введите число n для определения корня: ";
|
||||||
|
std::cin >> n;
|
||||||
cout << "Рекурсивный: " << root_hf_div(n, 1, n) << endl;
|
|
||||||
}
|
std::cout << "Обычный: " << root(n) << std::endl;
|
||||||
|
std::cout << "Рекурсивный: " << root_hf_div(n, 1, n) << std::endl;
|
||||||
|
}
|
||||||
|
|||||||
11
alg_4_4.cpp
11
alg_4_4.cpp
@@ -1,5 +1,4 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int f(int n, int sum)
|
int f(int n, int sum)
|
||||||
{
|
{
|
||||||
@@ -12,7 +11,11 @@ int f(int n, int sum)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int n; cin >> n;
|
setlocale(LC_ALL, "Russian");
|
||||||
|
int n;
|
||||||
|
|
||||||
cout << f(n, 0);
|
std::cout << "Введите число n для определения суммы его цифр: ";
|
||||||
}
|
std::cin >> n;
|
||||||
|
|
||||||
|
std::cout << "Сумма: " << f(n, 0);
|
||||||
|
}
|
||||||
|
|||||||
12
alg_4_5.cpp
12
alg_4_5.cpp
@@ -1,5 +1,4 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int f(int n)
|
int f(int n)
|
||||||
{
|
{
|
||||||
@@ -10,6 +9,11 @@ int f(int n)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int n; cin >> n;
|
setlocale(LC_ALL, "Russian");
|
||||||
cout << f(n);
|
int n;
|
||||||
}
|
|
||||||
|
std::cout << "Введите число n для определения значения функции Дейкстры: ";
|
||||||
|
std::cin >> n;
|
||||||
|
|
||||||
|
std::cout << "Значение функции Дейкстры: " << f(n) << std::endl;
|
||||||
|
}
|
||||||
|
|||||||
34
alg_4_6.cpp
34
alg_4_6.cpp
@@ -1,26 +1,26 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
void move(int a, int b, int c, int n)
|
void move(int a, int b, int c, int n)
|
||||||
{
|
{
|
||||||
if (n == 1)
|
if (n == 1)
|
||||||
{
|
{
|
||||||
cout << "from " << a << " to " << c << endl;
|
std::cout << "Из " << a << " в " << c << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
move(a, c, b, n - 1);
|
move(a, c, b, n - 1);
|
||||||
|
std::cout << "Из " << a << " в " << c << std::endl;
|
||||||
cout << "from " << a << " to " << c << endl;
|
move(b, a, c, n - 1);
|
||||||
|
}
|
||||||
move(b, a, c, n - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int n;
|
setlocale(LC_ALL, "Russian");
|
||||||
cout << "Enter the amount of disks: "; cin >> n;
|
int n;
|
||||||
|
|
||||||
|
std::cout << "Количество дисков: ";
|
||||||
|
std::cin >> n;
|
||||||
|
|
||||||
move(1, 2, 3, n);
|
move(1, 2, 3, n);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user