CASIO fx-5800P GCD

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Greatest Common Divisor with User Input for the Casio fx-5800P Calculator

https://github.com/slugrustle/fx-5800P_progs Version 2

1 0➔DimZ: 49 Locate 1,1,B:


2 27➔DimZ: 50 Locate 12,1,C:
3 0➔A: 51 Locate 13,1,”:”:
4 ”ENTER -1 AFTER LAST INPUT”: 52 Locate 14,1,E:
5 While 1: 53 3×(C−1)+1➔A:
6 ”NUMBER”?➔B: 54 Locate 1,2,Z[A]:
7 B=-1⇒Break: 55 A+1≤D⇒Locate 1,3,Z[A+1]:
8 If B≠Int(B): 56 A+2≤D⇒Locate 1,4,Z[A+2]:
9 Then Cls: 57 While 1:
10 ”NUMBER MUST BE AN INTEGER”: 58 Getkey➔F:
11 Stop: 59 If F=34 Or F=73:
12 IfEnd: 60 Then Cls:
13 If B<1 Or B≥1X1010: 61 ”DONE”:
14 Then Cls: 62 Stop:
15 ”NUMBER MUST BE >0 And <1X1010”: 63 IfEnd:
16 Stop: 64 If F=77 Or F=84 Or F=86 Or F=47:
17 IfEnd: 65 Then C+1➔C:
18 A+1➔A: 66 C>E⇒1➔C:
19 If A≤27: 67 Goto 1:
20 Then B➔Z[A]: 68 IfEnd:
21 Else Cls: 69 If F=67 Or F=83 Or F=85:
22 ”SUPPORTS AT MOST27 NUMBERS”: 70 Then C−1➔C:
23 Stop: 71 C<1⇒E➔C:
24 IfEnd: 72 Goto 1:
25 WhileEnd: 73 IfEnd:
26 If A<2: 74 WhileEnd
27 Then Cls:
28 ”REQUIRES 2 OR MORE NUMBERS”: Program Outline
29 Stop: Lines 1–2: Set up memory for extra
30 IfEnd: variables Z[α] where α ∈ [1,27].
31 A➔D: Lines 3–31: User input of arguments for
32 Z[D]➔B: GCD(Z[1], ..., Z[D]). D ∈ [2,27].
33 For D−1➔A To 1 Step -1:
34 Z[A]➔C: Lines 32–43: Evaluate B = GCD(Z[1],
35 While B≠C: ..., Z[D]). Uses GCD(β,γ,δ,ε) =
36 If B≥C: GCD(GCD(GCD(β,γ),δ),ε).
37 Then B−C×Int(B÷C)➔B:
Lines 44–74: Display result and inputs.
38 B=0⇒C➔B:
39 Else C−B×Int(C÷B)➔C: Variable Descriptions
40 C=0⇒B➔C: A: Index into extra variable memory.
41 IfEnd:
42 WhileEnd: B: User input and GCD evaluation.
43 Next: C: GCD evaluation and number of dis-
44 1➔C: played input argument page.
45 Int(D÷3)➔E:
46 D−3×E>0⇒E+1➔E: D: Number of input arguments.
47 Lbl 1:
E: Number of input argument display
48 Cls:
pages (3 inputs per page).

1 / 2
F: Identifier of most recently pressed
key.
Notes
Lines 4, 10, 15, 22, and 28: The weird
spacing prevents text wrapping from
occurring in the middle of a word.
Line 13: The fx-5800P can only
represent numbers on the range
[−1X1010,1X1010] as exact integers.
Line 59: Pressing DEL (34) or EXIT (73)
ends the program.
Line 64: Pressing + (77), ▲ (84),
▶ (86), or EXE (47) cycles to the next
input argument display page.
Line 69: Pressing − (67), ◀ (83), or
▼ (85) cycles to the previous input
argument display page.

Written in 2018 by Ben Tesch. To the extent possible


under law, the author has dedicated all copyright
and related and neighboring rights to this software
to the public domain worldwide. This software is
distributed without any warranty. Published under
the CC0 1.0 Universal Public Domain Dedication; see
http://creativecommons.org/publicdomain/zero/1.0/

2 / 2

You might also like