Advertisement
Guest User

Untitled

a guest
May 9th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. //найти сумму членов ряда 1 + 1/2 + 1/3 +...+ 1/n
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int sum(double n);
  7.  
  8. int main()
  9. {
  10. double a;
  11. cout << "Enter number: " << endl;
  12. cin >> a;
  13.  
  14. cout << sum(a) << endl;
  15.  
  16. system("pause");
  17. return 0;
  18. }
  19.  
  20. int sum(double n)
  21. {
  22. double f = 0;
  23. if (n == 1){
  24. f = 1;
  25. }
  26. else{
  27. f = 1 / n + sum(n - 1);
  28. }
  29. return f;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement