Fixed my old formatting and patched things that were left as-is due to burnout and laziness

This commit is contained in:
2024-12-06 15:14:33 +03:00
parent 02068890a5
commit 69d40c2dfb
7 changed files with 85 additions and 71 deletions

View File

@@ -1,55 +1,57 @@
#include <iostream>
using namespace std;
#include <cmath>
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;
}
std::cout << "Введите число n для определения корня: ";
std::cin >> n;
std::cout << "Обычный: " << root(n) << std::endl;
std::cout << "Рекурсивный: " << root_hf_div(n, 1, n) << std::endl;
}