Math 171 Spring 2005, Lab 9

Due Saturday, February 26, 11:59 P.M.

  1. Overview
  2. Assignment
  3. Hints

Overview

The purpose of this lab is to introduce you to using named loops, DO-WHILE loops, counting loops, and the CYCLE and EXIT statements in fortran.

Top

Assignment

Write a fortran program called pyth3 that finds all pythagorean triples x2+y2=z2 with the values of x,y, and z lying in a specified range. Your program must satisfy the following requirements:

Top

Hints

  1. Begin by prompting the user for the specified range, and write a nested counting loop that iterates through/writes out all possible x,y values in this range.
  2. Now check whether each x,y pair is part of a pythagorean triple, and modify your code to only write out the appropriate x,y pairs.
  3. Next, edit the boundary values on one of your loops to avoid checking redundant solutions.
  4. Add conditional CYCLE statements to implement any optimizations. You will probably need to use named loops here.
  5. Now go back and add a test to skip over any values that are not primitive.
  6. Finally, test your program against the various lists of primitive pythagorean triples available on the web, such as this one.

Top

Back to the course information page