Ex 6) This exercise uses sub-algorithms. Trace it for when input value is 6 and complete the trace tables. Also note that there are two variables name num, one in the main algorithm and another in the sub-algorithm. They are not related. Assume input is a positive integer. Write pre- post-conditions for each of these algorithms (the main one and the sub-algorithm). Note that the prime sub-algorithm is similar to the algorithm in Ex 1) but instead of reading input and producing outputs, it has a parameter num, and it returns the result. Also note that the true is in gray color, which means it can be ignored. Note that since the sub-program is called several times, it's better that you use separate trace tables, one for each call, as shown below. start num 142 i<+1+1 is num T prime()-true F prime(num) start flag-true d+2 flog true and ds num/2 num mod d=0 3 umed value

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 17PE
icon
Related questions
Question
num
Ex 6) This exercise uses sub-algorithms. Trace it for when input value is 6 and complete the trace tables. Also
note that there are two variables name num, one in the main algorithm and another in the sub-algorithm.
They are not related. Assume input is a positive integer. Write pre- post-conditions for each of these
algorithms (the main one and the sub-algorithm). Note that the prime sub-algorithm is similar to the
algorithm in Ex 1) but instead of reading input and producing outputs, it has a parameter num, and it
returns the result. Also note that the =true is in gray color, which means it can be ignored. Note that since
the sub-program is called several times, it's better that you use separate trace tables, one for each call, as
shown below.
output
start
num
142
i<(i+1
is num
end
T
prime()=true
F
prime(num)
start
flag-true
d-2
flag = true and
ds num/2
num mod d = 0
flag-false
ded+1
ret flag
3
returned value
flag
Mag
#
#
returned value
Transcribed Image Text:num Ex 6) This exercise uses sub-algorithms. Trace it for when input value is 6 and complete the trace tables. Also note that there are two variables name num, one in the main algorithm and another in the sub-algorithm. They are not related. Assume input is a positive integer. Write pre- post-conditions for each of these algorithms (the main one and the sub-algorithm). Note that the prime sub-algorithm is similar to the algorithm in Ex 1) but instead of reading input and producing outputs, it has a parameter num, and it returns the result. Also note that the =true is in gray color, which means it can be ignored. Note that since the sub-program is called several times, it's better that you use separate trace tables, one for each call, as shown below. output start num 142 i<(i+1 is num end T prime()=true F prime(num) start flag-true d-2 flag = true and ds num/2 num mod d = 0 flag-false ded+1 ret flag 3 returned value flag Mag # # returned value
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Quicksort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning