CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Pythagorean triples in code c, help!

1. Junior Member
Join Date
Sep 2014
Posts
2

## Pythagorean triples in code c, help!

I need to create a code in c fits the description below, I have no idea what to do, if someone could possibly write a code or explain to me what I could do that would be appreciated!

Description
A positive integer triple (a, b, c) with 0 < a < b < c and a^2 + b^2 = c^2
is called a Pythagorean triple. Write a
program in C which reads an integer N and prints
1. the total number of Pythagorean triples (a, b, c) with c < N,
2. every such Pythagorean triple, and
3. the triple that has the largest value of c.
Hint: you can enumerate all possible pairs (a, b) with 0 < a < b < N and check if they satisfy a
2+b
2 < N2
.
Example Input/Output
• Enter a positive integer: [3]
There is no Pythagorean triple in this range.
• Enter a positive integer: [15]
There are 3 Pythagorean triples in this range:
(3, 4, 5)
(5, 12, 13)
(6, 8, 10)
The triple with the largest value of c is (5, 12, 13).
• Enter a positive integer: [6]
There are 1 Pythagorean triples in this range:
(3, 4, 5)
The triple with the largest value of c is (3, 4, 5).

2. ## Re: Pythagorean triples in code c, help!

This seems like a homework assignment. Please see http://forums.codeguru.com/showthrea...ork-assignment

With what exactly are you having difficulty? You are given a good description of the problem. Just saying you have no idea isn't really going to illicit much help as nobody here is going to do your homework assignment for you.

First think about how you would solve this problem using pen and paper. Then design the program from this, code it and finally test and debug it. Once you have produced some code if you post it here we;ll provide further advice and guidance.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width