Post Reply 
(42S) Fractions
07-11-2016, 05:06 AM
Post: #1
(42S) Fractions
HP 42S: Fractions

The program FRACT provides three calculations involving fractions:

ADD: add two fractions
W/X + Y/Z = (W*Z + X*Y)/(X*Z)

MULT: multiply two fractions
W/X * Y/Z = (W*Y)/(X*Z)

POWER: take a fraction to a power
(W/X)^Y = W^Y/X^Y

The end of the program stores the resulting numerator in N and the resulting denominator in D. FRACT simplifies the fraction after calculation. Note: FRACT sets the HP 42S to FIX 0 mode. Mixed fractions are not included.

Code:
HP 42S:  Program FRACT
00 {255-Byte Prgm}
01 LBL “FRACT”
02 FIX 00
03 LBL 99 \\ start menu 
04 CLMENU
05 LBL 00
06 “ADD”
07 KEY 1 GTO 01  \\ KEYG 
08 “MULT”
09 KEY 2 GTO 02 
10 “POWER”
11 KEY 3 GTO 03
12 MENU
13 STOP
14 GTO 99  \\ end menu
15 LBL 01  \\ addition routine
16 CLMENU
17 “W/X + Y/Z”
18 AVIEW
19 PSE
20 INPUT “W”
21 INPUT “X”
22 INPUT “Y”
23 INPUT “Z”
24 RCL “W”
25 RCL* “Z”
26 RCL “X”
27 RCL* “Y”
28 +
29 STO “N”
30 RCL “X”
31 RCL* “Z”
32 STO “D”
33 GTO 10 \\ go to GCD routine
34 LBL 02 \\ multiply routine
35 CLMENU
36 “W/X x Y/Z”
37 AVIEW
38 PSE
39 INPUT “W”
40 INPUT “X”
41 INPUT “Y”
42 INPUT “Z”
43 RCL “W”
44 RCL* “Y”
45 STO “N”
46 RCL “X”
47 RCL* “Z”
48 STO “D”
49 GTO 10 \\ go to GCD routine
50 LBL 03 \\ power routine
51 CLMENU
52 “(W/X)/\Y”  \\ the power symbol is made of two symbols: / and \
53 AVIEW
54 PSE
55 INPUT “W”
56 INPUT “X”
57 INPUT “Y”
58 RCL “W”
59 RCL “Y”
60 Y^X
61 STO “N”
62 RCL “X”
63 RCL “Y”
64 Y^X
65 STO “D”
66 GTO 10  \\ go to GCD routine
67 LBL 10 \\ GCD routine
68 RCL “N”
69 RCL “D”
70 X<Y?
71 X<>Y
72 STO 01
73 X<>Y
74 STO 00
75 LBL 11
76 RCL 01
77 ENTER
78 RCL÷ 00
79 IP
80 RCL* 00
81 –
82 X=0?
83 GTO 12
84 X<>Y
85 STO 01
86 X<>Y
87 STO 00
88 GTO 11
89 LBL 12 \\ ending and display
90 CLA \\ clear ALPHA register
91 RCL “N”
92 RCL÷ 00 \\ GCD = R00
93 STO “N”
94 ARCL ST X
95 ├ “/”   \\ ├ is the attach symbol, press [shift] [ENTER] (ALPHA) [ENTER]
96 RCL “D”
97 RCL÷ 00
98 STO “D”
99 ARCL ST X
100 AVIEW
101 END

Test 1: Addition (ADD)
12/19 + 8/17 = 356/323
W = 12, X = 19, Y = 8, Z = 17
Result: “356./323.” Y: 356, X: 323

Test 2: Multiplication (MULT)
12/19 * 8/17 = 96/323
W = 12, X = 19, Y = 8, Z = 17
Result: “96./323.” Y: 96, X: 323

Test: Power (POWER)
(2/7)^3 = 8/343
W = 2, X = 7, Y = 3
Result: “8./343.”, Y: 8, X: 343
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)