Pythagorean Triples Program

A problem in Hanly & Koffman Chapter 2 explains how to compute "Pythagorean Triples," given any two positive integers.

The Pythagorean theorem states that the sum of the squares of the sides of a right triangle is equal to the square of the hypotenuse. For example, if two sides of a right triangle have lengths of 3 and 4, then the hypotenuse must have a length of 5. Together the integers 3, 4, and 5 form a Pythagorean triple. There are an infinite number of such triples. Given two positive integers, m and n, where m > n, a Pythagorean triple can be generated by the following formulas:

side1 = m2 - n2
side2 = 2mn
hypotenuse = m2 + n

For example, the triple ( side1 = 3, side2 = 4, hypotenuse = 5) is generated by this formula when m = 2 and n = 1.
Write a program that takes values for m and n as input and displays the values of the Pythagorean triple generated by the formulas above.


We want to enhance this problem so that it will find the Pythagorean Triples that correspond to your initials.

Consider the letters of the alphabet as being numbered according to their position, A=1, B=2, etc. Write a program which accepts two initials from the user, computes the corresponding integers, and then outputs the Pythagorean triple for those integers.
 

Test Plan

Manually computer the triple for Barbara Alcott and the one for her father Charles. Compute the triple for your initials.

Design

The program has three functions and a main function.

Functions: findSide1(), findSide2(), findSide3()

Algorithm: Determine the three parts of the triple, according to the formulas provided above.
 

Main function:

Algorithm:


Directions

  1. Find a seat next to your assigned lab partner for this week.
  2. Design meeting (10 minutes). Divide up the work.  One person will write the functions and one will write the main.  Study the design above and fill in any details which may have been omitted.
  3. Implementation (20-30 minutes). Work individually to implement your part of the solution.  Write C program statements on your own paper. You may use the textbook.  You can't talk to your partner during this phase, but you can pass hand written notes.
  4. Verification (10 minutes). Rejoin your partner and review each other's work (you can talk now), making any corrections as necessary.  Time permitting, take your work to the lab and compile and run it, comparing your results to your test plan.
  5. Retain your work to submit at the next class meeting.