Advertisement
VictoriaLodochkina

lab 11 z2 ALL RIGHT)

Jan 12th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double rec(long);
  7.  
  8. int main()
  9. {
  10.     long n;
  11.     cout << "Enter n: " << endl;
  12.     cin >> n;
  13.     double x;
  14.     x = rec(n);
  15.     cout << "Your result: " << 1.0/3 + (n*n)/x << endl;
  16.     return 0;
  17. }
  18.  
  19. double rec(long i)
  20. {
  21.     static long n = i;
  22.     if (i == 1)
  23.     {
  24.         return (1.0 /3);
  25.     }
  26.     else
  27.     {
  28.         return (1.0 / (pow(3, i))) * rec(i - 1);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement