Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <limits>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int main() {
  9.     double x, r = 0, p = 1;
  10.     int n, i;
  11.  
  12.  
  13.     do {
  14.         if (cin.fail()) {
  15.             cin.clear();
  16.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  17.         }
  18.  
  19.         cout << "Enter x and n: ";
  20.         cin >> x >> n;
  21.     } while (cin.fail() || n <= 0);
  22.  
  23.  
  24.     for (i = 1; i <= n; i++) {
  25.         p *= (x / i);
  26.         r += p;
  27.     }
  28.     r = r + 1;
  29.  
  30.  
  31.     cout << "r = " << fixed << setprecision(4) << r << endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement