Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double sum(int n)
- {
- if (n < 1)
- return 0.0;
- else
- return pow(-1, n) / n + sum(n - 1);
- }
- int main()
- {
- int n;
- cout << "n = ";
- cin >> n;
- double res = sum(n);
- cout << res << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement