CS 159 – HW #01
5 Points Possible
Due: January 24, 2011 at 11:00pm.
Background (From:
http://en.wikipedia.org/wiki/Pythagorean_triple
):
A
Pythagorean triple
consists of three
positive integers
a
,
b
, and
c
, such that
a
2
+
b
2
=
c
2
. Such a triple is commonly written (
a
,
b
,
c
), and a wellknown
example is (3, 4, 5).
Euclid's formula
is a fundamental formula for generating Pythagorean triples given an arbitrary pair of positive
integers
m
and
n
with
m
>
n
. The formula states that the integers below form a Pythagorean triple.
Problem:
Given the two integer values described above as
m
and
n
input, calculate the lengths of side #1 (a),
side #2 (b), and the hypotenuse (c).
•
Both inputs will be positive integer values.
You may assume that the second integer will be less than
the first.
•
You are permitted to use mathematical function for power if desired.
Example Execution #1:
Enter the first positive integer value: 3
Enter the second positive integer value (less than 3): 1
The Pythagorean triple given positive integers [3 and 1]:
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 CRUM
 Computer Science, Euclidean algorithm, Euclid, positive integer value

Click to edit the document details