// Step 1: Setting and Declaration
DECLARE Numbers : ARRAY[1:5] OF INTEGER
DECLARE SearchItem, Count : INTEGER
DECLARE Found : BOOLEAN
// Step 2: Input the array values
FOR Count ← 1 TO 5
OUTPUT “Enter number “, Count, “: “
INPUT Numbers[Count]
NEXT Count
// Step 3: Input the value to search
OUTPUT “Enter the number to search: “
INPUT SearchItem
// Step 4: Initialize Found as FALSE
Found ← FALSE
// Step 5: Linear Search
FOR Count ← 1 TO 5
IF Numbers[Count] = SearchItem THEN
Found ← TRUE
OUTPUT “Item found at position “, Count
EXIT FOR
ENDIF
NEXT Count
// Step 6: If not found
IF Found = FALSE THEN
OUTPUT “Item not found in the list.”
ENDIF
Step-by-Step Explanation
-
Declare the array and variables
-
The array
Numbersstores 5 integers. -
SearchItemstores the value the user wants to find. -
Foundis a Boolean variable to track if the item is found or not.
-
-
Input phase
-
The program takes 5 numbers as input and stores them in the array.
-
-
Search input
-
The user enters the number to search.
-
-
Initialize search condition
-
Found ← FALSEassumes the number is not found initially.
-
-
Perform linear search
-
The program goes through each element in the array.
-
If a match is found,
Foundbecomes TRUE, and the position is displayed.
-
-
Final output
-
If the number wasn’t found after checking all elements, the program displays “Item not found in the list.”
-
