23 lines
348 B
Text
23 lines
348 B
Text
0 => int total;
|
|
fun int factorial(int i)
|
|
{
|
|
if (i == 0) return 1;
|
|
else
|
|
{
|
|
i * factorial(i - 1) => total;
|
|
}
|
|
return total;
|
|
}
|
|
|
|
// == another way
|
|
fun int factorial(int x)
|
|
{
|
|
if (x <= 1 ) return 1;
|
|
else return x * factorial (x - 1);
|
|
}
|
|
|
|
// call
|
|
factorial (5) => int answer;
|
|
|
|
// test
|
|
if ( answer == 120 ) <<<"success">>>;
|