factorial(n)={1n<=0n∗factorial(n−1)n>0factorial(n)=egin{cases} 1 & n<=0\n*factorial(n-1) & n>0end{cases}factorial(n)={1n∗factorial(n−1)n<=0n>0
long factorial(int n) { if( n<=0 ) return 1; else return n*factorial(n-1); }
long factorial(int n) { int result = 1; while( n>1 ) { result *= n; n -= 1; } return result; }