blob: c68f8eeeb2c4f686ddd8300022d817c0df6d546a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
% Accepts a number and calculates its factorial
function factorial (n: int) : real
if n = 0 then
result 1
else
result n * factorial (n - 1)
end if
end factorial
var n: int
loop
put "Please input an integer: " ..
get n
exit when n >= 0
put "Input must be a non-negative integer."
end loop
put "The factorial of ", n, " is ", factorial (n)
|