This is the problem I need to solve. It comes directly out of a C++ Programming book:

A right triangle can have sides that are all integers. A set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sume of the squares of two of the sides equal to the square of the hypotenuse. Find all Pythagorean triples for Side1, side2, and hypotenuse all no larger than 500. Use a triple nested loop that tries all possibilities.

Any help would be much appreciated.... I am fully halted on this problem.

## All 3 Replies

This is the problem I need to solve. It comes directly out of a C++ Programming book:

Any help would be much appreciated.... I am fully halted on this problem.

Never mind I completely had an epiphany and got it done.

Start by understanding the mathametics of the triangle -- see this wiki article. That article gives you the solution for the 16 primitive Pythagorean triples with c ≤ 100. That should give you the data you need to verify the accuracy of your program.

One way to do it would be the long way, create two loops that count from 1 to 500. Inside the inner-most loop calculate the equation c^2 = a^2 + b^2. (where ^ means squared).

Never mind I completely had an epiphany and got it done.

Good for you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.