fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. long long factorial(int n) {
  5. if (n == 0 || n == 1)
  6. return 1;
  7. return n * factorial(n - 1);
  8. }
  9.  
  10. int main() {
  11. long long sum = 0;
  12.  
  13. for (int i = 1; i <= 10; i++) {
  14. long long f = factorial(i);
  15. cout << i << "! = " << f << endl;
  16. sum += f;
  17. }
  18.  
  19. cout << "Сума факторіалів = " << sum << endl;
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
Сума факторіалів = 4037913