Data update
This commit is contained in:
parent
07c7092a52
commit
61b93a2cd1
313 changed files with 6160 additions and 346 deletions
23
Task/Middle-three-digits/BASIC256/middle-three-digits.basic
Normal file
23
Task/Middle-three-digits/BASIC256/middle-three-digits.basic
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue