Largest int from concatenated ints: Difference between revisions

added FreeBASIC
(added FreeBASIC)
Line 513:
Biggest:9 8 7 6 5 4 3 2 1 10
</pre>
=={{header|FreeBASIC}}==
<lang freebasic>' 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</lang>
{{out}}
<pre>Largest concatenated int from {1,34,3,98,9,76,45,4} = 989764543431
Largest concatenated int from {54,546,548,60} = 6054854654</pre>
 
=={{header|Go}}==
457

edits