You are given a stack of 100 cards. On each card is written a positive number be
ID: 3782578 • Letter: Y
Question
You are given a stack of 100 cards. On each card is written a positive number between 1 and 100. Define an algorithm that you would use to find the largest number in the stack. Make sure that your algorithm is clear and unambiguous. Identify any selection or repetition in it. Represent the algorithm using pseudocode. The cards in the stack would look somewhat like the following: 1 27 5 n The actual numbers written on the cards are not important for your algorithm. What is important is that they are equal or greater than 1, no number is repeated, and the cards are not sorted in any way.Explanation / Answer
Algorithm:
Let X, Y and Z are three numbers. This algorithm finds the largest number among these three numbers. In this algorithm at first X is compared with Y if X is greater than Y then X is Compared with Z. If X is greater than Z, thus X is largest number otherwise Y is compared with Z. If Y is greater than Z then Y is the largest number. If X and Y both are less than Z then Z is the Largest number.
Step 1: Start
Step 2: Take Input X, Y and Z
Step 3: [comparison among X, Y and Z starts from here]
If X > Y then:
If X > Z then:
Print: X is the Largest Number.
[End of If Structure]
Else if Y > Z then:
Print: Y is the Largest Number.
Else
Print: Z is the Largest Number.
[End of If Else Structure]
Step 4: Exit
Pseudo code (In python language):
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.