home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_02_04
/
2n04039b
< prev
next >
Wrap
Text File
|
1991-02-05
|
540b
|
28 lines
'
' Casting 9's, table lookup version.
'
DEFINT I-K
DEFLNG L
FUNCTION CAST2 (L) STATIC
' On first call, set up table values
IF IFIRSTCALL = 0 THEN
IFIRSTCALL = 1
REDIM ISUM(0 TO 99)
ISUM(0) = 0
FOR I = 1 TO 91 STEP 9
FOR J = 1 TO 9
ISUM(I+J-1) = J
NEXT J
NEXT I
END IF
' Then loop over pairs of digits
K = 0
L1 = L
WHILE L1 > 99
K = ISUM(K + ISUM(L1 MOD 100))
L1 = L1 \ 100
WEND
CAST2 = ISUM(K + ISUM(L1))
END FUNCTION