Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int n;
- float sum = 0;
- do
- {
- cout << "Enter n: ";
- cin >> n;
- if (n < 0)
- {
- cout << "Enter again!" << endl;
- }
- } while (n < 0);
- for (int i = 1; i <= n; i++)
- {
- sum = sum + (1.0 / (i * (i + 1)));
- }
- cout << "\nS(n) = 1 / 1 * 2 + 1 / 2 * 3 + ... + 1 / n * (n + 1) = " << setprecision(3) << sum << endl;
- cout << endl;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment