Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Middle-three-digits/Gambas/middle-three-digits.gambas
Normal file
24
Task/Middle-three-digits/Gambas/middle-three-digits.gambas
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Public Sub Main()
|
||||
Dim iList As Integer[] = [123, 12345, 1234567, 987654321, 10001,
|
||||
-10001, -123, -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0] 'Array of integers to process
|
||||
Dim sTemp As String 'Temp string
|
||||
Dim siCount As Short 'Counter
|
||||
Dim sAnswer As New String[] 'Array, resons for failure or 'middle three digits'
|
||||
|
||||
For siCount = 0 To iList.Max 'Loop through the integers
|
||||
sTemp = Str(Abs(iList[siCount])) 'Convert integer to positive and place in sTemp as a string
|
||||
If Len(sTemp) < 3 Then 'If sTemp has less than 3 characters then..
|
||||
sAnswer.Add("This integer has less than 3 characters") 'Place text in sAnswers
|
||||
Else If Even(Len(sTemp)) Then 'Else If sTemp is of even length then
|
||||
sAnswer.Add("This integer has an even length") 'Place text in sAnswers
|
||||
Else 'Else..
|
||||
sAnswer.Add(Mid(sTemp, Int(Len(sTemp) / 2), 3)) 'Place the middle 3 digits in sAnswer
|
||||
Endif
|
||||
Next
|
||||
|
||||
For siCount = 0 To iList.Max 'Loop through the integers
|
||||
Print Space$(10 - Len(Str(iList[siCount]))) &
|
||||
iList[siCount] & " : " & sAnswer[siCount] 'Print out results
|
||||
Next
|
||||
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue