RosettaCodeData/Task/Largest-int-from-concatenated-ints/FreeBASIC/largest-int-from-concatenated-ints.freebasic
2017-09-25 22:28:19 +02:00

78 lines
1.6 KiB
Text

' version 17-01-2016
' compile with: fbc -s console
' TRUE/FALSE are built-in constants since FreeBASIC 1.04
' But we have to define them for older versions.
#Ifndef TRUE ' if TRUE is not defined then
#Define FALSE 0
#Define TRUE Not FALSE
#EndIf
Dim As Integer array()
Function largest(array() As Integer) As String
Dim As Integer lb = LBound(array), ub = UBound(array)
Dim As Integer i, flag
Dim As String a_str(lb To ub),tmp
For i = lb To ub
a_str(i) = Left(Str(array(i)) & String(14, " "), 14)
Next
Do
flag = TRUE
For i = lb To ub - 1
If a_str(i) < a_str(i+1) Then
Swap a_str(i), a_str(i +1)
flag = FALSE
End If
Next
If flag = TRUE Then Exit Do
Loop
For i = lb To ub
tmp += Trim(a_str(i))
Next
Return tmp
End Function
' ------=< MAIN >=------
Data 1, 34, 3, 98, 9, 76, 45, 4, -999
Data 54, 546, 548, 60, -999
Data -999
Dim As Integer i, x
Do
ReDim array(1 To 1)
i = 1
Do
Read x
If x = -999 Then Exit Do
If i > 1 Then
ReDim Preserve array(1 To i)
End If
array(i) = x
i += 1
Loop
If i = 1 Then Exit Do
Print "Largest concatenated int from {";
For i = lBound(array) To UBound(array)
Print Str(array(i));
If i = UBound(array) Then
Print "} = "; largest(array())
Else
Print ",";
End If
Next
Loop
' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End