How to find the largest value in an array Flowchart
Overview
In this post, we will create a flowchart to find the largest value in an array. We will use the RAPTOR flowchart. We will keep track the largest value in an array using a tracking variable LargestValue. We will assign the first value of the array to this variable.
The first value in the array is :
array_variable[1]
For example: marks[1]
To read values into an array, follow the link:
https://www.testingdocs.com/questions/how-to-read-values-into-an-array-using-raptor-flowchart/
After the loop iteration we will have the maximum array element in the tracking variable. We can use the output symbol to print the maximum element.
Flowchart
Let’s create the flowchart to find the maximum element in the array : marks
FindMax is the RAPTOR procedure that takes marks array as an input parameter. We can call this procedure using the Call symbol.
In a loop we will check every element in the array if the element is greater than this variable. If the array element is greater than we store this array element in the tracking variable.
LargestValue <- marks[index]
If the array element is less than the tracking variable then we already have the maximum value so far in the tracking variable.
Pseudocode
FUNCTION FindMax(marks) DECLARE index DECLARE LargestValue LargestValue = marks(1) index = 1 DO UNTIL index > 5 IF marks(index) > LargestValue THEN LargestValue = marks(index) ELSE END IF index = index + 1 LOOP OUTPUT "The largest value in the array=" + LargestValue END FUNCTION
Common mistakes:
In RAPTOR flowchart, array index starts with 1 and not with zero. We can’t use marks[0] to denote the first element, unlike in other programming languages like C, Java etc.
can't use 0 as an array index
We know that Alice has 5 subjects. So the index starts with 1 and ends with 5. We can’t access the array with a higher number than the index. For example, we can’t access marks[6]. This will return an error because the array doesn’t have 6 elements.
marks doesn't have 6 elements.
Raptor Tutorials on this website can be found at: