Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
54
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. using namespace std;
  3.  
  4. int fattRecur(int n);
  5.  
  6. int main()
  7. {
  8.     int n;
  9.     double sumOfFactorials = 2;
  10.     cout << "Iserire il numero per il quale si vuole eseguire il calcolo: ";
  11.     cin >> n;
  12.     for (int i = 2; i != (n + 1); i++)
  13.     {
  14.         double thisFactorial = fattRecur(i);
  15.         double thisReciproc = 1 / thisFactorial;
  16.         sumOfFactorials += thisReciproc;
  17.     }
  18.     cout << "Il risultato e': " << sumOfFactorials;
  19. }
  20.  
  21. int fattRecur(int n)
  22. {
  23.     return n == 1 ? 1 : n * fattRecur(n - 1);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement