Task 1 What is the output for the following pseudocode? Given a set of data, sho
ID: 3813969 • Letter: T
Question
Task 1
What is the output for the following pseudocode? Given a set of data, show your steps that lead you to the end result.
Here’s an example:
Given.
d = 1
e = 2
f = 5
while d<f
d= d+1
e=e+f
endwhile
output d,e,f
Show your work:
Start with 1. 1 is less than 5
1st execution:
2 = 1+1
7 = 2+5
5=5
2nd execution:
Start with 2. 2 is less than 5
3=2+1
12=7+5
5=5
3rd execution:
Start with 3. 3 is less than 5
4 = 3+1
17=12+5
5=5
4th execution:
Start with 4. 4 is less than 5
5=4+1
22=17+5
5=5
5th execution:
Start with 5. 5 is NOT less than 5.
Execution stops and output results in:
Final Answer:
5,22,5
Explanation / Answer
Consider the data as
d = 5
e = 4
f = 10
First execution
d<f 5< 10 false
Control will not go inside while loop and value remains unchanged
Output 5,4,10
Consider data set
d = 2
e = 6
f = 10
First iteration
d<f i.e 2<10 true
d = d+1 : d = 2+1
d= 3
e = e+f
e = 6+10
e = 16
Second iteration
d<f i.e 3<10 true
d = d+1
d = 3+1
d= 4
e = e+f
e = 16+10
e = 26
Third Iteration
d<f: 4<10 true
d = d+1
d = 4+1
d = 5
e =e + f
e = 26+10
e = 36
Fourth Iteration
d<f : 5<10
d = d+1
d = 6
e= e+ f
e = 36+10
e = 46
Fifh Iteration
d<f : 6<10 true
d = 6+1
d = 7
e = e+ f
e = 46+10
e = 56
Sixth Iteration
d<f : 7<10 true;
d = 7+1
d = 8
e= e+f
e= 56+10
e = 66
Seventh Iteration
d<f : 8<10 true
d = 8+1
d = 9
e = e+f
e = 66+10
e = 76
Eight Iteration
d<f : 9<10 true
d = d+1
d = 9+1
d = 10
e =e + f
e = 76+10
e = 86
Ninth Iteration
d<f : 10<10 false
exit loop
Output : d,e,f
i.e 10,86,10
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.