Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <limits>
- using namespace std;
- int main() {
- double x, r = 0, p = 1;
- int n, i;
- do {
- if (cin.fail()) {
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- cout << "Enter x and n: ";
- cin >> x >> n;
- } while (cin.fail() || n <= 0);
- for (i = 1; i <= n; i++) {
- p *= (x / i);
- r += p;
- }
- r = r + 1;
- cout << "r = " << fixed << setprecision(4) << r << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement