Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions algorithms/c/LinearSearch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<stdio.h>
#include<string.h>

int lsearch(int arr[], int el, int len)
{
for(int i = 0; i < len; i++)
{
if(arr[i] == el)
return i;
}

return -1;
}

int main()
{
int n, el;

printf("Enter the length of array: ");
scanf("%d", &n);

int arr[n];

printf("Enter the elements of array: ");
for(int i = 0; i < n; i++)
scanf("%d", &arr[i]);

printf("Which element of array you want to search: ");
scanf("%d", &el);

printf("Element %d exists at index %d", el, lsearch(arr, el, n));

return 0;
}