TI-BASIC:Pythagorean Triples

From Learn @ Cemetech
Jump to navigationJump to search

Routine Summary

Displays the Pythagorean triples.


C - how many triples you want to display



Variables Used

A, B, C

Calculator Compatibility

TI-83/84/+/SE Author

WeregooseURL: United TI Download

file pythagoreantriples.zip

:Disp {A²-B²,2AB,A²+B²
:If getKey:Pause

A [wikipedia:Pythagorean_triple Pythagorean triple] occurs when, while using the [wikipedia:Pythagorean_theorem 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.