1 REM .---------------------------------------------------------------------.
2 REM | PITICO v0.1 (preview build) - Sample: GOSUB FACTORIAL TEST          |
3 REM | Since the current version does not support loading code from files, |
4 REM | you can do the following to run this code in PITICO:                |
5 REM | 1. Copy everything from this file to the clipboard;                 |
6 REM | 2. Reset the interpreter's memory (CLEAR statement);                |
7 REM | 3. Paste the clipboard contents inside PITICO;                      |
8 REM | 4. Call RUN statement.                                              |
9 REM '---------------------------------------------------------------------'
10 L=200
20 PREC 0
30 INPUT "N? ", N
40 IF N<0 END ELSE IF N>22 GOSUB 100
50 X=1
60 F=1
70 GOSUB L
80 PRINT "Factorial of"; N; "is"; F, ".\n"
90 GOTO 30
100 PRINT "WARNING! Factorials above 22! may lose precision due to rounding errors...\n"
110 RETURN
199 REM Lines 200-240 implements a recursive factorial function.
200 IF X>N THEN RETURN
210 F=F*X
220 X=X+1
230 GOSUB L
240 RETURN
