fun linearSearch(array: IntArray, value: Int): Int {
for (index in array.indices) {
if (array[index] == value) {
return index
}
}
return -1
}
fun main() {
val arr = intArrayOf(5, 3, 15, 2, 9, 8)
val searchValue = 15
val resultIndex = linearSearch(arr, searchValue)
if (resultIndex != -1) {
println("Value $searchValue found at index $resultIndex")
} else {
println("Value $searchValue not found in the array.")
}
}