- Check one by one.
- If found then return
index
. - else
return -1
.
int search(int arr[], int n, int k) {
for(int i = 0; i < n; i++)
if(arr[i] == k)
return i + 1;
return -1;
}
index
.return -1
.int search(int arr[], int n, int k) {
for(int i = 0; i < n; i++)
if(arr[i] == k)
return i + 1;
return -1;
}