Linear search of a number from an array, it might be success or failed.
Your algorithm should define success or failed return. Such as position index for success and negative number for failed.
Try to think like this: Moving until you find the position.
Your number define as target. Given length and array A.
int linearSearch(int target, int* A, int length) {
int pos = length - 1;
while ( pos >= 0 and target != A[pos] ) --pos;
return pos;
}
Here, If your target number is not in array, you'll get a -1 returned.
This will simple and elegant. But if you have duplicate target number, you may think how to handle them. Return one of you found or return all position.