Advertisement
edgarrii

Untitled

Feb 28th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8.     setlocale(0, "rus");
  9.  
  10.     int n;
  11.  
  12.     double Root_R(int);
  13.     double Root(int);
  14.  
  15.  
  16.     cout << "Введите число n:" << endl;
  17.     cin >> n;
  18.  
  19.  
  20.  
  21.     cout << "Это рекурсия: \t\t"    << Root_R(n) << endl;
  22.     cout << "Это не рекурсия:\t" << Root(n) << endl;
  23.  
  24.    
  25. }
  26.  
  27. double Root_R(int n)
  28. {
  29.     if (n < 2) return 1;
  30.     else
  31.         return sqrt(sqrt(n) + Root_R(n - 1));
  32. }
  33.  
  34.  
  35. double Root(int n)
  36. {
  37.     double y = 0, z = 0;
  38.  
  39.     for (int i = n; i > 0; i--)
  40.     {
  41.         y = sqrt(z + i);
  42.         z = y;}
  43.  
  44.     return y;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement