num 6 Ex 6) This exercise uses sub-algorithms. Trace it for when input value is 6 and complete the trace tables. Also no
Posted: Sun Jul 03, 2022 11:21 am
num 6 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 prime()= true end F prime(num) start flag-true d-2 flag = true and d's num/2 num mod d = 0 flag-false ded+1 ret flag num flag 4 returned value 2 3 لا 4 flag flag d # returned value returned value