Course Content
Paper 2 – Problem Solving Approach -Practical
0/102
Past Paper-2 May/June 2025
Past Paper-1 May/June 2025
Download Files
0/1
Olevel : Computer Science 2210 / IGCSE 0478 : Recorded

// 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

  1. Declare the array and variables

    • The array Numbers stores 5 integers.

    • SearchItem stores the value the user wants to find.

    • Found is a Boolean variable to track if the item is found or not.

  2. Input phase

    • The program takes 5 numbers as input and stores them in the array.

  3. Search input

    • The user enters the number to search.

  4. Initialize search condition

    • Found ← FALSE assumes the number is not found initially.

  5. Perform linear search

    • The program goes through each element in the array.

    • If a match is found, Found becomes TRUE, and the position is displayed.

  6. Final output

    • If the number wasn’t found after checking all elements, the program displays “Item not found in the list.”

You cannot copy content of this page