Store five floating numbers in an array and find the largest one.

  A[0] A[1] A[2] A[3] A[4] declare by double A[5];
element 7.2 6.8 8.1 4.5 3.7    
index 0 1 2 3 4    

A

Text Box: Note: you can sort them in ascending order and list the last number as the largest number of these five numbers.  However, this way will waste a lot of CPU time.  (Why?)
Text Box: Largest
Text Box: 7.2
   

 

1. Store the first number in Largest box.
2. Compare A[1] with Largest.  If A[1] is larger than Largest, then replace Largest by A[1], otherwise, do nothing.
3. Compare A[2] with Largest.  If A[2] is larger than Largest, then replace Largest by A[2], otherwise, do nothing.
4. Compare A[3] with Largest.  If A[3] is larger than Largest, then replace Largest by A[3], otherwise, do nothing.
5. Compare A[4] with Largest.  If A[4] is larger than Largest, then replace Largest by A[4], otherwise, do nothing.
6. The answer for the largest number will be in Largest box.