Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
53
Task/Floyds-triangle/FreeBASIC/floyds-triangle.basic
Normal file
53
Task/Floyds-triangle/FreeBASIC/floyds-triangle.basic
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
' 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue