Practice

Linear Search in an Array

2024/Feb/Mar·Variant 2
MEDIUMArrays

Read 5 numbers into an array called Values, then read a search number MyNumber. Use a linear search to find if MyNumber is in the array.

Input: 5 numbers (array), then the search target. Output: The 1-based position if found, or "Not found".

Example:

Input:  10
        20
        30
        40
        50
        30
Output: 3
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Found in middle
Inputs: 10, 20, 30, 40, 50, 30
Expected: 3
Test 2: Not in array
Inputs: 5, 15, 25, 35, 45, 99
Expected: Not found
Press Ctrl+Enter to run your code
or Ctrl+Shift+Enter to grade