Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double rec(long);
- int main()
- {
- long n;
- cout << "Enter n: " << endl;
- cin >> n;
- double x;
- x = rec(n);
- cout << "Your result: " << 1.0/3 + (n*n)/x << endl;
- return 0;
- }
- double rec(long i)
- {
- static long n = i;
- if (i == 1)
- {
- return (1.0 /3);
- }
- else
- {
- return (1.0 / (pow(3, i))) * rec(i - 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement