Skip to content
Merged
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
15 changes: 11 additions & 4 deletions Search/LinearSearch/C/linear_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ int search(int arr[], int n, int key)

int main()
{
int arr[] = {4, 10, 8, 25, 13, 89, 45, 12, 78, 11};
int key = 78;
int size;
printf("Enter the size of the array\n");
scanf("%d\n",&size);
int arr[size],key;
int n = sizeof(arr) / sizeof(int);

printf("Enter the elememts of the array\n");
for(int i=0;i<n;i++){
scanf("%d\n",arr[i]);
}
printf("Enter the element you want to search");
scanf("%d\n",&key);
int res = search(arr, n, key);

if (res == -1)
Expand All @@ -26,4 +33,4 @@ int main()
printf("%d is found at position %d.\n", key, res + 1);

return 0;
}
}