I have the following C++ code to find factorial of a number:
#include <iostream>
using namespace std;
int factorial(int n){
if (n<=1)
{return 1;
}
return n*factorial(n-1);
}
int main()
{
int a;
cout<<"Enter a no: ";
cin>>a;
cout<<"The value of "<<a<<"! is "<<factorial(a);
return 0;
}
It works fine for values upto 12! But show wrong values above it. e.g. -- 20! is showing -2102132736 ( a negative no)
,for some big values like 50! show 0.
What could be the probable reason ???