function factorial(long x) returns long {
if( x == 1) {
return 1;
} else {
return x*(factorial( x-1 ));
}
}
Next, I just ran it by using:
println("The factorial of 12 is: " + factorial(12) + ".");
and this gave me the expected result of:
The factorial of 12 is: 479001600.
so, this seems to work fine.
Next thing will be to try recursion for facts, and of course for rules... More about that later.
Inga kommentarer:
Skicka en kommentar