We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 52d39e8 commit 0456985Copy full SHA for 0456985
search/linear_search.c
@@ -0,0 +1,30 @@
1
+#include <stdio.h>
2
+
3
+int main()
4
+{
5
+ int array[100], search, c, n;
6
7
+ printf("Enter the number of elements in array\n");
8
+ scanf("%d",&n); // Total no of elements
9
10
+ printf("Enter %d integer(s)\n", n);
11
12
+ for (c = 0; c < n; c++)
13
+ scanf("%d", &array[c]); // Reading the elements
14
15
+ printf("Enter the number to search\n"); // Target element to be searched
16
+ scanf("%d", &search);
17
18
19
+ {
20
+ if (array[c] == search) /* if required element found */
21
22
+ printf("%d is present at location %d.\n", search, c+1);
23
+ break;
24
+ }
25
26
+ if (c == n)
27
+ printf("%d is not present in array.\n", search); // Element not found
28
29
+ return 0;
30
+}
0 commit comments