CJCoding With Joseph
15per day

Linear Search

An array called nums has already been created for you with the values {10, 20, 30, 40, 50}. A variable called target has been set to 30.

Your task is to search through the array to find where the target value is located. This is called a linear search: you check each element one by one until you find what you're looking for.

Loop through the array and compare each element to the target. When you find a match, print the result and stop searching. If you reach the end without finding it, print "Not found".

Since 30 is at index 2, the expected output is:
Found at index 2

Expected Output:

Found at index 2
Topics:
Arrays
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.