
/* Script function: Computes the factorial (series) of an integer with recursive and iterative methods.
The factorial of a number N is the product of all the whole numbers 
between 1 and N. For example, 4 factorial is 1×2×3×4, or 24. */

// Unless named starting with GlobalSino, EM, My, Self, the function commands are defined 
//by Gatan DM, please see at link: http://www.globalsino.com/EM/page2597.html


// Recursive version.
number EMfactr(number n)
{
number EManswer;
if(n==1) return (1); // return 1 is the same as return (1).
EManswer = EMfactr(n-1)*n;
return(EManswer);
}

// Iterative version.
number EMfact(number n)
{
number t, answer;
answer = 1;
for(t=1; t<=n; t++) answer = answer*(t);
return(answer);
}

void main ()
{
number x
x = 5

// use recursive version
result ("5 factorial is " + EMfactr(x) + "\n")

// use iterative version
result ("5 factorial is " + EMfact(x) + "\n\n")
}

main ()