← Back to Arrays
Question 112
Linear Search
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 exactly what is shown in Expected Output.Expected Output:
Found at index 2= newline. No newline after the last line.
Hints3 available
Sign in to use hintsTopics:
Arrays
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.