Advertisement
Serafim_

Число e

Nov 17th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double factorial(int n){
  5.   double res = 1;
  6.     int i = 1;
  7.     while (i <= n){
  8.         res *= i;
  9.         i++;
  10.     }
  11.     return 1.0/res;
  12. }
  13.  
  14.  
  15. void fill(double a[],int n){
  16.     double sum=0;
  17.     for (int i = 0; i < n+1; i++) {
  18.  
  19.         a[i] = factorial(i);
  20.          sum=sum+a[i];
  21.     }
  22. cout<<sum<<endl;
  23. }
  24.  
  25.  
  26.  
  27. int main()
  28.  
  29.  
  30. {
  31.     int n;
  32.     cout << "Введите количество элементов  : ";
  33.     cin >> n;
  34.     double * a = new double[n+1];
  35.  
  36.     fill(a, n);
  37.     delete [] a;
  38.  
  39.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement