Post Reply 
(71B) Euclid Division and Fraction Addition/Multiplication
07-01-2016, 02:04 AM (This post was last modified: 07-10-2016 12:42 AM by Eddie W. Shore.)
Post: #1
(71B) Euclid Division and Fraction Addition/Multiplication
Euclid Division – Finding the GCD

Finds the GCD (greatest common divisors) between integers M and N. The program displays a “calculating” screen while the calculation is in process.

Code:
Program EUCLID (143 bytes)
10 DESTROY M,N,A,B,C
15 INPUT “M,N:”; M,N
20 IF M>N THEN A=M  @ B=N
22 IF M<N THEN A=N @ B=M
30 C= A – IP(A/B)*B
35 DISP C;B;A   // this is the “busy” indicator
40 IF C=0 THEN 50
45 A=B @ B=C @ GOTO 30
50 DISP “GCD:”; B

Test 1: M=144, N=14; Result: 2
Test 2: N=14, M=144; Result: 2

Fraction Addition and Multiplication

Adds or multiplies two fractions W/X and Y/Z. Gives the result in the simplest form. Proper or improper fractions only.

Separate each part with a comma (W,X,Y,Z) as prompted.

Code:
Program FRAC (380 bytes)
10 DESTROY W,X,Y,Z,N,D,H,A,B,C
20 INPUT “1. + 2. *:”,H
24 ON H GOTO 41,51
41 REM ADD
42 INPUT “W/X+Y/Z:”; W,X,Y,Z
44 N=W*Z+X*Y @ D=X*Y
46 GOSUB 61
48 DISP “=”; N; “/”; D @ STOP
51 REM MULT
52 INPUT “W/X*Y/Z:”; W
54 N=W*Y @ D=X*Z
56 GOSUB 61
58 DISP “=”; N; “/”; D @ STOP
61 REM SIMPLIFY
62 IF N>D THEN A=N @ B=D
64 IF D>N THEN A=D @ B=N
66 IF D=N THEN N=1 @ D=1 @ RETURN
68 C= A – IP(A/B)*B
69 DISP C;B;A
70 IF C=0 THEN 74
72 A=B @ B=C @ GOTO 68
74 N=N/B @ D=D/B @ RETURN

Test 1: 4/7 + 3/13; Input: 4,7,3,13. Result: 73/91
Test 2: 4/7 * 3/13; Input: 4,7,3,13. Result: 12/91
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)