Example 26: Generate Pythagorean Triple

Learn how to calculate the Pythagorean triple.

Problem

Write a program to generate all Pythagorean triple with side lengths less than or equal to 20.

Example

Input Output
Nil 3 4 5
4 3 5
5 12 13
6 8 10
8 6 10
8 15 17
9 12 15
12 5 13
12 9 15
12 16 20
15 8 17
16 12 20

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Note: Try to generate all the Pythagorean triple in the coding widget given below. The order, however, does not matter as it depends on your logic.

Get hands-on with 1400+ tech skills courses.