ceesort/src/lsrch.c

17 lines
336 B
C
Raw Normal View History

2022-05-29 20:01:58 +01:00
/*
* Filename: lsrch.c
* Author(s): Roland (r.weirhowell@gmail.com)
* Description: Perform linear search on an integer array
* License: MIT (https://spdx.org/licenses/MIT.html)
*/
#include "lsrch.h"
int lsrch(int* arr, int n, int target)
{
2022-05-29 21:17:44 +01:00
for (int i = 0; i < n; i++)
if (arr[i] == target) return i;
2022-05-29 20:01:58 +01:00
2022-05-29 21:17:44 +01:00
return -1;
2022-05-29 20:01:58 +01:00
}