Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > cd14cddf3b3ceaf1193157472227757a > files > 656

parrot-doc-1.6.0-1mdv2010.0.i586.rpm

# Copyright (C) 2008, Parrot Foundation.
# $Id: factorial.sq 36833 2009-02-17 20:09:26Z allison $

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))