Final answer:
The algorithm determines and outputs prime numbers containing the digit 7 from an input array by utilizing two sub-algorithms: one to check for prime numbers and another to check for the digit 7.
Step-by-step explanation:
The problem at hand involves developing an algorithm to process an array of integers, identify prime numbers, and further filter those prime numbers that contain the digit 7. A main algorithm will call upon two sub-algorithms: prime(num) to check if a number is prime, and has7(num) to check if the number contains the digit 7.
Main Algorithm
If the number is prime, call the has7(num) sub-algorithm.
If has7(num) returns true, output the number.
Sub-Algorithm: prime(num)
Pre-condition: num is an integer. Post-condition: Returns true if num is a prime number; otherwise, returns false.
Sub-Algorithm: has7(num)
Pre-condition: num is an integer. Post-condition: Returns true if num contains the digit 7; otherwise, returns false.
To trace the has7(num) algorithm, create a separate trace table for each call to record the execution flow and determine the output for different input numbers. The main algorithm loop checks both conditions using the specified sub-algorithms before outputting the qualifying prime numbers with the digit 7.