fork download
  1. #include<iostream>
  2. using namespace std;
  3. long fact(int n)
  4. {
  5. if(n==0)
  6. return 1;
  7.  
  8. return (n*fact(n-1));
  9. }
  10. int main()
  11. {
  12. int num;
  13. cout<<"Enter a positive integer: ";
  14. cin>>num;
  15.  
  16. cout<<"Factorial of "<<num<<" is "<<fact(num)<<endl;
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 3472KB
stdin
2
stdout
Enter a positive integer: Factorial of 2 is 2