Pythagorean triples in code c, help!

View previous topic View next topic Go down

Pythagorean triples in code c, help!

Post by Shamil555 on Sun Sep 28, 2014 8:41 am

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).

Shamil555

Posts : 1
Join date : 2014-09-28

View user profile

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum