Advertisement
genets

Untitled

Jan 29th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double sum(int n)
  5. {
  6.     if (n < 1)
  7.         return 0.0;
  8.     else
  9.         return pow(-1, n) / n + sum(n - 1);
  10. }
  11.  
  12. int main()
  13. {
  14.     int n;
  15.     cout << "n = ";
  16.     cin >> n;
  17.  
  18.     double res = sum(n);
  19.     cout << res << endl;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement