Invitation to Computer Science 8th Edition

Published by Cengage Learning
ISBN 10: 1337561916
ISBN 13: 978-1-33756-191-4

Chapter 2 - Exercises - Page 88: 23

Answer

$\bullet$ Get the elements of the list $N_{1}, N_{2}, \ldots N_{k}$ $\bullet$ Get the value of $S U M$ $\bullet$ Set the value of Found to $N O$ $\bullet$ Set the value of $i$ to 1 $\bullet$ While both $(i \leq k)$ and (Found $=N O )$ do $\bullet \quad$ Set the value of $j$ to $i+1$ $\bullet\quad$ While both $(j \leq k)$ and $(\text { Found }=N O)$ do $\bullet \quad\quad$ If $N_{i}+N_{j}=S U M$ then $\bullet \quad\quad\quad$Set value of Found to YES $\bullet \quad\quad\quad$ Set value of term $_{1}$ to $N_{i}$ and term_ to $N_{j}$ $\bullet\quad\quad$ Increment $j$ by 1 $\bullet\quad$ End of loop $\bullet \quad$ Increment $i$ by 1 $\bullet$ End of loop $\bullet$ If Found $=Y E S$ then $\bullet\quad$ Print the result $\left(\operatorname{term}_{1}, \text { term }_{2}\right)$ $\bullet$ Else $\bullet\quad$ Print "Sorry, there is no such pair"

Work Step by Step

$\bullet$ Get the elements of the list $N_{1}, N_{2}, \ldots N_{k}$ $\bullet$ Get the value of $S U M$ $\bullet$ Set the value of Found to $N O$ $\bullet$ Set the value of $i$ to 1 $\bullet$ While both $(i \leq k)$ and (Found $=N O )$ do $\bullet \quad$ Set the value of $j$ to $i+1$ $\bullet\quad$ While both $(j \leq k)$ and $(\text { Found }=N O)$ do $\bullet \quad\quad$ If $N_{i}+N_{j}=S U M$ then $\bullet \quad\quad\quad$Set value of Found to YES $\bullet \quad\quad\quad$ Set value of term $_{1}$ to $N_{i}$ and term_ to $N_{j}$ $\bullet\quad\quad$ Increment $j$ by 1 $\bullet\quad$ End of loop $\bullet \quad$ Increment $i$ by 1 $\bullet$ End of loop $\bullet$ If Found $=Y E S$ then $\bullet\quad$ Print the result $\left(\operatorname{term}_{1}, \text { term }_{2}\right)$ $\bullet$ Else $\bullet\quad$ Print "Sorry, there is no such pair"
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.