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

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

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started