3vHd >>F >>bD22 #########################################
33 ## R E C I P O C A L S ##
42 #########################################
5
d- S(100): dimension an array of integers
n. S is a list of all remainders encountered
x. S(W) will be the W'th number in this list
}
~9 ============ TITLE AND INSTRUCTIONS ================
:
( (20);"C A L C U L A T I O N O F"
I (2);"D E C I M A L F R A C T I O N S T O 1 0 0 P L A C E S"
\"Instructions:"
= (10);"You tell me a number, I calculate its reciprocal"
' (10);"to 100 places of decimals."
. (10);"Repeating fractions are whitened."
9 ====================================================
: Do ten calculations only, then its someone else's go
' A=1 10: --- begin main loop ---
: ==== GET DENOMIMATOR FROM KEYBOARD AND CHECK ========
"Number please: ";D4$;
0 String input protects against bad key entry
" Check for satisfactory number
D1=(D4$)
. (D1)<>0 " No fractions allowed":190
* D1>3640 " That's too large!!":190
D=(D1)
1 D<2 " Integer to be larger than 1.": 190
: =====================================================
NUMBER IS SATISFACTORY
7 ========== CALCULATION ===========================
"i Z=-1 : Z is -1 for normal print, 0 for inverse print
,, begin to calculate reciprocal and print
6 (8)"1/";D;" = 0.";
@' N=0 : counter for dec. digits
Jf L=0 : logical variable: repeating sequence not found yet, -1 if found
Ti S(0)=0 : will contain the remainder you get at the start of repeating digits
^+ W=1 : counter for remainder array
h` R=1 : the first calculation seems to have remainder equal to 1
r7 S(W)=R : store this first remainder in the array
|. Begin loop to calculate up to 100 digits.
N=N+1
next decimal digit is Q
T=R*10 : bring down the 0
Q=T/D
calculate remainder, R
R=T-Q*D
Q;
stop if remainder is 0
R=0 : 550
w if still searching for repeating sequence then save remainder to check for repeating decimal later
k (L) 2000: update remainder array set L=-1 if match found
# R<>S(0) 530 : next digit
4 beginning of repeat cycle: change print mode
Z :Z=0 :Z=-1
. N=100 :: 550: 100 digits printed
1 380 : return to start of loop 100 digits
!: =====================================================
"
& A: --- end main loop ---
08 \"That's 10 goes. Let the next person have a turn."
:$ "Press space bar for next turn."
D ="" 580
N
X; ******************************************************
Ы subroutine : search the list of remainders. If the current remainder is in the list then the decimal is repeating, else add it to the list.
L=0:J=1W
R=S(J)L=-1:S(0)=R
J
(L)W=W+1:S(W)=R
8 # # # # # # # # # # # # # # # # # # # # # # # # # #
8 # Written by Roger Perry January 1984 #
8 # 108 Barons Crescent, Hunters Hill #
8 # N.S.W. 2110 (02) 89 5752 #
8 # # # # # # # # # # # # # # # # # # # # # # # # # #
There is also a