30 lines
848 B
Plaintext
30 lines
848 B
Plaintext
sub middleThreeDigits$ (n)
|
|
if n < 0 n = -n
|
|
if n < 100 return "" // error code
|
|
if n < 1000 return str$(n)
|
|
if n < 10000 return ""
|
|
ns$ = str$(n)
|
|
if mod(len(ns$), 2) = 0 return "" // need to have an odd number of digits for there to be 3 middle
|
|
return mid$(ns$, len(ns$) / 2, 3)
|
|
end sub
|
|
|
|
dim a(16)
|
|
a(0) = 123 : a(1) = 12345 : a(2) = 1234567
|
|
a(3) = 987654321 : a(4) = 10001 : a(5) = -10001
|
|
a(6) = -123 : a(7) = -100 : a(8) = 100
|
|
a(9) = -123451
|
|
a(10) = 2 : a(11) = -1 : a(12) = -10
|
|
a(13) = 2002 : a(14) = -2002 : a(15) = 0
|
|
|
|
print "The 3 middle digits of the following numbers are : \n"
|
|
|
|
for i = 1 to 16
|
|
result$ = middleThreeDigits$(a(i))
|
|
print a(i), "\t => ";
|
|
if result$ <> "" then
|
|
print result$
|
|
else
|
|
print "Error: does not have 3 middle digits"
|
|
fi
|
|
next
|