(15C) Pythagorean Triples - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (15C) Pythagorean Triples (/thread-8004.html) |
(15C) Pythagorean Triples - Eddie W. Shore - 03-23-2017 03:34 AM 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:
Example: Input: R0 = M = 4, R1 = N = 1, R2 = 2. Output: 30, 16, 34 |