Example 62: Linear Search

Learn how to implement a linear search algorithm.

Problem

Linear search is the simplest method of searching an element in an array. In this method, the element is sequentially searched in the array. This method can be applied to a sorted or unsorted list.

Write a function that performs a linear search on an array of 10 integers. It should either return the position of the first occurrence of an element if it is found or -1.

Demonstration

Get hands-on with 1400+ tech skills courses.