10 Write an algorithm in pseudocode with the following input
10. Write an algorithm in pseudo-code with the following input and output : Input: a1, a2, …, an, a sequence of numbers. Output: The Largest number in the sequence.
Solution
Using Arrays:
To find the Largest value, you initialize a placeholder called max with the value of the first element in the array. Then you go through the array element by element. If any element is larger than max you replace max with that element. Here is the pseudocode:
Without Arrays:
FindLargest
Input: a1, a2, …, an, a sequence of numbers
1. Set Largest to 0
2. Set Counter to 0
3. while (Counter less than n)
3.1 if (the integer is greater than Largest)
then
3.1.1 Set Largest to the value of the integer
End if
3.2 Increment Counter
End while
4. Return Largest
End
