N! = N * (N-1) * (N-2) * .....*2 * 1
This is a very simple recursive program:
int Factorial(int n){
if(n == 0){
return i;
}else{
return n * Factorial(n-1);
}
}
Not all Recursive method are very efficient, such as the recursive in Fibonacci:
Fibonacci: F(n) = F(n-1) + F(n-2), n > 1
So for some aspects, recursive is not always a good way, it depends on the problems you want to solve.
No comments:
Post a Comment