Added my works from 2022
This commit is contained in:
55
alg_4_3.cpp
Normal file
55
alg_4_3.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user