#include <iostream>
using std::cout;
using std::endl;
int LinearSearch(int arr[], int len, int target)
{
for (int i = 0; i < len; i++)
{
if (target == arr[i])
{
return i;
}
}
return -1;
}
int main(void)
{
int arr[] = { 3, 5, 2, 4, 9 };
int index = LinearSearch(arr, sizeof(arr) ⁄ sizeof(arr[0]), 4);
if (index == -1)
{
cout << "Search Failed" << endl;
}
else
{
cout << "Target Save Index : " << index << endl;
}
index = LinearSearch(arr, sizeof(arr) ⁄ sizeof(arr[0]), 7);
if (index == -1)
{
cout << "Search Failed" << endl;
}
else
{
cout << "Target Save Index : " << index << endl;
}
}