Skip to content

Commit b7851fc

Browse files
committed
Added LinearSearch in C
1 parent 39b77f0 commit b7851fc

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

LinearSearch/C/LinearSearch.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
#include <stdio.h>
3+
4+
int main()
5+
{
6+
int array[100] search, c, n=10; // n is the number of elements to be stored.
7+
8+
int array[n]; //array[] is used to store the element
9+
10+
printf("Enter the number to search\n");
11+
scanf("%d", &search);
12+
13+
for (c = 0; c < n; c++)
14+
{
15+
if (array[c] == search) /* if required element found */
16+
{
17+
printf("%d is present at location %d.\n", search, c+1);
18+
break;
19+
}
20+
}
21+
if (c == n)
22+
printf("%d is not present in array.\n", search);
23+
24+
return 0;
25+
}

0 commit comments

Comments
 (0)