24 lines
688 B
Plaintext
24 lines
688 B
Plaintext
function middleThreeDigits(n)
|
|
if n < 0 then n = -n
|
|
if n < 100 then return "" ## error code
|
|
if n < 1000 then return string(n)
|
|
if n < 10000 then return ""
|
|
ns = string(n)
|
|
if length(ns) mod 2 = 0 then return "" ## need to have an odd number of digits for there to be 3 middle
|
|
return mid(ns, length(ns) \ 2, 3)
|
|
end function
|
|
|
|
dim a = {123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -123451, 2, -1, -10, 2002, -2002, 0}
|
|
|
|
print "The 3 middle digits of the following numbers are : "
|
|
print
|
|
for i = 0 to 15
|
|
result = middleThreeDigits(a[i])
|
|
print a[i]; chr(9); " => ";
|
|
if result <> "" then
|
|
print result
|
|
else
|
|
print "Error: does not have 3 middle digits"
|
|
end if
|
|
next
|