fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Solution{
  5. public:
  6. int factorial(int N){
  7. if(N == 0){
  8. return 1;
  9. }
  10.  
  11. int smallOutput = factorial(N - 1);
  12. int result = N * smallOutput;
  13. return result;
  14. }
  15. };
  16.  
  17. int main() {
  18. Solution sol;
  19. int n;
  20. cin>>n;
  21. cout << sol.factorial(n) << endl;
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5296KB
stdin
5
stdout
120