SHARE
TWEET

Untitled

a guest Sep 17th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top