' version 19-09-2015 ' compile with: fbc -s console Sub pascal_triangle(n As UInteger) Dim As UInteger a = 1, b, i, j, switch = n + 1 Dim As String frmt, frmt_1, frmt_2 ' last number of the last line i = (n * (n + 1)) \ 2 frmt_2 = String(Len(Str(i)) + 1, "#") ' first number of the last line i = ((n - 1) * n) \ 2 + 1 frmt_1 = String(Len(Str(i)) + 1, "#") ' we have 2 different formats strings ' find the point where we have to make the switch If frmt_1 <> frmt_2 Then j = i + 1 While Len(Str(i)) = Len(Str(J)) j = j + 1 Wend switch = j - i End If Print "output for "; Str(n) : Print For i = 1 To n frmt = frmt_1 b = (i * (i + 1)) \ 2 For j = a To b ' if we have the switching point change format string If j - a = switch Then frmt = frmt_2 Print Using frmt; j; Next j Print a = b + 1 Next i Print End Sub ' ------=< MAIN >=------ pascal_triangle(5) pascal_triangle(14) ' empty keyboard buffer While Inkey <> "" : Wend Print : Print "hit any key to end program" Sleep End