IUP Computer Science
CO 310 Fall 1982

Assignment #2
(Due 27 September 1982)

The greatest common divisor (gcd) of two positive numbers is the largest number that evenly divides both numbers. The following list shows several examples:

    First #       Second #      gcd
     30              48          6
    103              85          1
    728             770         14
     18              72         18
Euclid devised an algorithm for calculating the greatest common divisor of two numbers, a and b. The algorithm consisted of the following steps:
   1. Let x ← a and y ← b.
   2. Divide x by y leaving remainder, r.
   3. If r = 0, y is the gcd of a and b.
   4. If r ≠ 0, let x ← y and y ← r and go back to step 2.

Write a PL6 program that repeatedly reads in two numbers from the terminal and prints out the gcd of the two numbers. Input and output should be identified. If either of the read-in numbers is zero, exit the program. Provide several input values of your own choosing. NOTE: The gcd must be calculated by using a recursive procedure.

Write a PL6 program to do the following:
1. Read in the records of file 310MONFUN.COMPSCI and store the information in a structure. Each record contains a function name in colums 1-6 and a function number in columns 8-10. There are fewer than 100 records, and they are in alphabetical order by function name.

2. Repeatedly, read in a function name from the terminal and call a binary search procedure to find the name in the structure. Terminate the program on a sentinel value of your own choosing.

3. Print the function number of each name that is found or an error message for each name that is not found. Identify the output. Use the following function names as terminal input:

   BOUT, FFFFP, MONRD, SNOOP, WAIT, ATI, PSOUT