Pythagorean Triples

Routine Summary

Displays the Pythagorean triples.

Inputs

C - how many triples you want to display

Outputs

None

Variables Used

A, B, C

Calculator Compatibility

TI-83/84/+/SE

Author

Weregoose

URL: United TI

pythagoreantriples.zip

``````:For(A,2,C
:For(B,1,A-1
:Disp {A²-B²,2AB,A²+B²
:If getKey:Pause
:End:End```
```

A Pythagorean triple occurs when, while using the Pythagorean Theorem a2+b2=c2 to find the three sides of a right triangle, all three values are whole integers. For example, a common triple is 3,4,5 — in this case, 9 (32) + 16 (42) = 25 (52). The general formula that can be derived to figure out when a triple occurs is: a=(A2-B2) b=(2AB) c=(A2+B2).

Now that you know what a Pythagorean triple is, the routine should be pretty clear. We are essentially looping over the range of values that we want to find triples in, and then displaying the triples as a three element list using the above mentioned formula. Because there can be many triples found, and displaying all of them would just be like a blur on the screen, the Pause command allows you to temporarily halt the program so you can see the triples that are currently displayed.

.