Files
ARPZ_s1_pr4/alg_4_3.cpp

55 lines
892 B
C++

#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;
}