Sophie

Sophie

distrib > Mageia > 1 > i586 > by-pkgid > d92aa75c2d384ff9f513aed09a46f703 > files > 603

parrot-doc-3.1.0-2.mga1.i586.rpm

# Copyright (C) 2008, Parrot Foundation.

print("Please enter number: ")
x = read()

sub factorial(n)
    ## test for < 2 because all numbers are represented by
    ## floating-point numbers, and equality checks on those
    ## do not work (yet?)
    if n < 2 then
        return 1
    else
        return n * factorial(n - 1)
    end
end

print("factorial of ", x, " is: ", factorial(x))