Factorial in S-lang

Example for versions S-lang 2.2.2

This example shows array operations in S-lang. [1:i] creates a list of numbers from 1 to i; note that the default data type for array operations is double even if the numbers are integer. Intrinsic function prod (since version 2.1) returns the product of elements of its parameter. Intrinsic function sprintf provides C-style printing, %.0f printing floating point number with zero digits after decimal comma.

for (i=0; i<17; i++)
    sprintf ("%d! = %.0f", i, prod ( [1:i] ) );