Advertisement
Guest User

Useful Summation of Factorials

a guest
Oct 19th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. long int f(int n)
  5. {
  6.     return (n > 1 ? n*f(n-1) : 1);
  7. }
  8.  
  9. long int fCount(int n)
  10. {
  11.     long int count = 0;
  12.     for(int i = 1; i <= n; i++)
  13.     {
  14.         count += f(i);
  15.     }
  16.     return count;
  17. }
  18.  
  19. int main()
  20. {
  21. int N;
  22. cout<< "Enter Your Number: ";
  23. cin>>N;
  24.     cout << fCount(N);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement