Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. In class we developed a procedure or algorithm to find the largest of three n

ID: 3706341 • Letter: 1

Question

1. In class we developed a procedure or algorithm to find the largest of three numbers. Suppose we want to pick the largest of four numbers instead of three. We can of course, use the same logic and develop the algorithm. It is clearly evident that the algorithm for four numbers is going to be bigger (with more steps.), but not too long. If we, however, try to find the largest of five numbers using the same strategy (there is nothing wrong in doing that!) the algorithm will become to large (a bit confusing). For instance, if we want to find the largest of a set of numbers assuming that we do not know how many numbers are there in the set. Our logic is no good. Thus,it fails the test of generality. An alternative logic is needed to solve this problem. Develop an algorithm to pick the largest of set of numbers.

Explanation / Answer

Suppose we have an array A with the size m. Take a variable largest.

Step 1 :- Take the input from user that how many elements he want to input.

Step 2 :- Assign the value to n

Step 3 :- Take n values from the user and assign it to array A

Step 4 :- Assign the value of first index of array A to largest

Step 5 :- Repeat the steps 6 and 7 until i is less than n

Step 6 :-           check whether largest is less than A[i]

Step 7 :-                    if the condition is true then assign A[i] to the largest

Step 8 :-           end of if condition

Step 9 :-   end of loop

Step 10 :- Now display the variable largest which contain the largest value amoung the inputted values.