Find largest number in an array
Find largest number in an Array
Problem Statement
Design an algorithm to find maximum value among a set of N numbers.
Solution
Algorithm Name: Search Max(A, N, R).
Input : A is an array contains N (>=0) number of real numbers.
Output: R will hold the index of the first maximum value in the the array A.
Step 1: R = 0.
Step 2: i = 1.
Step 3: WHILE ( i< N )
IF ( A[i] > A[R] ) Then
R = i
EndIf
i = i + 1
EndWhile.
Step 4: Return.
Qus. 1 : <p>What will be the output of the following algorithm for a=5, b-8, c=6 ?</p><pre><span style="font-size: 12.6px;">Step 1: Start
Step 2: Declare variables a, b and c.
Step 3 Read variables a, b and c.
Step 4:
If a < b
If a <c
Display a is the smallest number.
Else
Display c is the smallest number.
Else
If b <c
Display b is the smallest number.
Else
Display c is the smallest number
Step 5:Stop</span><br></pre>
- a is the smallest number
- b is the smallest number
- c is the smallest number
- stop