Added my works from 2022

This commit is contained in:
2024-11-21 09:11:52 +03:00
parent facd000301
commit 02068890a5
7 changed files with 161 additions and 0 deletions

55
alg_4_3.cpp Normal file
View File

@@ -0,0 +1,55 @@
#include <iostream>
using namespace std;
double root(int n)
{
double L, R, B;
L = 0; R = n;
while (fabs(R - L) > 0.00001)
{
B = (L + R) / 2;
if ( B*B > n)
{
R = B;
}
else {
L = B;
}
}
return B;
}
double root_hf_div(double n, double L, double R)
{
double B;
if (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);
}
}
}
int main()
{
setlocale(LC_ALL, "Russian");
double n; cin >> n;
cout << "Обычный: " << root(n) << endl;
cout << "Рекурсивный: " << root_hf_div(n, 1, n) << endl;
}