'************************************************************ '* This small program displays a Pascal's triangle * '* up to 15 lines. * '* -------------------------------------------------------- * '* SAMPLE RUN: * '* * '* How many lines: 10 * '* * '* p 0 1 2 3 4 5 6 7 8 9 * '* n * '* ----------------------------------------------------- * '* 0 -- 1 * '* 1 -- 1 1 * '* 2 -- 1 2 1 * '* 3 -- 1 3 3 1 * '* 4 -- 1 4 6 4 1 * '* 5 -- 1 5 10 10 5 1 * '* 6 -- 1 6 15 20 15 6 1 * '* 7 -- 1 7 21 35 35 21 7 1 * '* 8 -- 1 8 28 56 70 56 28 8 1 * '* 9 -- 1 9 36 84 126 126 84 36 9 1 * '* -------------------------------------------------------- * '* Reference: "Exercices en Turbo Pascal By Claude Delannoy * '* Eyrolles, 1997". * '* * '* Basic Release By J-P Moreau, Paris. * '* (www.jpmoreau.fr) * '************************************************************ DEFDBL A-H, O-Z DEFINT I-N OPTION BASE 0 Nmax = 15 'max. number of lines DIM it(Nmax) 'one line of triangle ' nl desired number of lines ' i,j current line/column ' read number of lines & display caption CLS PRINT INPUT " How many lines: ", nl IF (nl > Nmax) THEN l = Nmax PRINT PRINT " p "; FOR i = 0 TO nl - 1 PRINT USING "#####"; i; NEXT i PRINT PRINT " n" PRINT " "; FOR i = 0 TO nl PRINT "-----"; NEXT i PRINT ' create and display each line FOR i = 0 TO nl - 1 it(i) = 1 FOR j = i - 1 TO 1 STEP -1 it(j) = it(j) + it(j - 1) NEXT j PRINT USING "###"; i; PRINT " --"; FOR j = 0 TO i PRINT USING "#####"; it(j); NEXT j PRINT NEXT i PRINT " "; FOR i = 0 TO nl PRINT "-----"; NEXT i PRINT END ' end of file pastri.bas