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 &lt; b If a &lt;c Display a is the smallest number. Else Display c is the smallest number. Else If b &lt;c Display b is the smallest number. Else Display c is the smallest number Step 5:Stop</span><br></pre>

  1. a is the smallest number
  2. b is the smallest number
  3. c is the smallest number
  4. stop

Programs

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad