Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Update linearSearch.c #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
13 changes: 8 additions & 5 deletions C-linear-search/linearSearch.c
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
//C program to implement linear search in an array
#include <stdio.h>
#include <conio.h>
#include <conio.h> /* Adding clrscr() and getch() */

int main()
{
int array[100], search, c, n;
clrscr();

printf("Enter the number of elements in array\n");
printf("Enter the number of elements in array (max 100) : \n");
scanf("%d", &n); /* Taking input for no of elements in array*/

printf("Enter %d integer(s) :\n", n);

for (c = 0; c < n; c++)
scanf("%d", &array[c]); /* Taking input for values of array at each index*/

printf("Enter a number to search\n");
scanf("%d", &search); /* Taking input for element to search*/
printf("Enter the element to be searched :\n");
scanf("%d", &search); /* Taking input for element to be searched*/

for (c = 0; c < n; c++)
{
if (array[c] == search) /* If element is found */
{
printf("%d is found at location %d.\n", search, c+1);
printf("%d is found at index %d and location %d.\n", search, c, c+1);
break;
}
}
if (c == n)
printf("%d isn't found in the array.\n", search);

getch();
return 0;
}