Guest User

Untitled

a guest
Jul 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. int factorial(int n)
  7. {
  8.     if (n<=1)
  9.     {
  10.         return 1;
  11.     }
  12.     else
  13.     {
  14.         return n*factorial(n-1);
  15.     }
  16. }
  17.  
  18. int main()
  19. {
  20.     setlocale(0, "rus");
  21.     double e;
  22.     cout << "Введите e: ";
  23.     cin >> e;
  24.     double sum = 0;
  25.     double temp;
  26.     int i = 1;
  27.     while ( (temp = 1.0/factorial(2*i)) >= e )
  28.     {
  29.         sum += temp;
  30.         i++;
  31.     }
  32.     cout << sum << endl;
  33.     system("PAUSE");
  34.     return 0;
  35. }
Add Comment
Please, Sign In to add comment