Guest User

Untitled

a guest
Nov 19th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. float sum = 0;
  9. do
  10. {
  11. cout << "Enter n: ";
  12. cin >> n;
  13. if (n < 0)
  14. {
  15. cout << "Enter again!" << endl;
  16. }
  17. } while (n < 0);
  18.  
  19. for (int i = 1; i <= n; i++)
  20. {
  21. sum = sum + (1.0 / (i * (i + 1)));
  22. }
  23. cout << "\nS(n) = 1 / 1 * 2 + 1 / 2 * 3 + ... + 1 / n * (n + 1) = " << setprecision(3) << sum << endl;
  24.  
  25. cout << endl;
  26. system("pause");
  27. return 0;
  28. }
Add Comment
Please, Sign In to add comment