Post Reply 
(15C) Pythagorean Triples
03-23-2017, 03:34 AM
Post: #1
(15C) Pythagorean Triples
This program calculates the Pythagorean triple (A, B, C) such that A^2 + B^2 = C^2 by the formulas:

A = K * (M^2 – N^2)
B = K * (2 * M * N)
C = K * (M^2 + N^2)

The conditions are M, N, and K are all positive integers where M > N.
Store M into memory 0, N into memory 1, and K into memory 2. A, B, and C are stored in memories 3, 4, and 5, respectively. If no such combination can be found, a single zero (0) is returned.

Code:

Step    Key    Code
001    LBL A    42, 21, 11
002    RCL 1    45, 1
003    RCL 0    45, 0
004    X≤0    43, 10
005    GTO 0    22, 0
006    RCL 0    45, 0
007    X^2    43, 11
008    RCL 1    45, 1
009    X^2    43, 11
010    -    30
011    STO 3    44, 3
012    LST X    43, 36
013    2    2
014    *    20
015    +    40
016    STO 5    44, 5
017    RCL 0    45, 0
018    RCL* 1    45, 20, 1
019    2    2
020    *    20
021    STO 4    44, 4
022    RCL 2    45, 2
023    STO* 3    44, 20, 3
024    STO* 4    44, 20, 4
025    STO* 5    44, 20, 5
026    RCL 3    45, 3
027    X^2    43, 11
028    RCL 4    45, 4
029    X^2    43, 11
030    +    40
031    RCL 5    45, 5
032    X^2    43, 11
033    -    30
034    X=0    43, 20
035    GTO 1    22, 1
036    LBL 0    42, 22, 1
037    0    0
038    RTN    43, 32
039    LBL 1    42, 21, 1
040    RCL 3    45, 3
041    R/S    31
042    RCL 4    45, 4
043    R/S    31
044    RCL 5    45, 5
045    RTN    43, 32

Example: Input: R0 = M = 4, R1 = N = 1, R2 = 2. Output: 30, 16, 34
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)