Repository navigation
Expand file tree
/
Copy pathlinear.c
More file actions
55 lines (49 loc) · 1.46 KB
/
Copy pathlinear.c
File metadata and controls
55 lines (49 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// #include<stdio.h>
// void main ()
// {
// int a[10] = {10, 23, 40, 1, 2, 0, 14, 13, 50, 9};
// int number, i,location;
// printf("Enter item which is to be searched:\n");
// scanf("%d",&number);
// for (i = 0; i< 10; i++)
// {
// if(a[i] == number)
// {
// location = i+1;
// break;
// }
// else
// location = 0;
// }
// if(location != 0)
// {
// printf("Item found at location: %d\n",location);
// }
// else
// {
// printf("Item not found\n");
// }
// }
#include <stdio.h>
int main ()
{
int array[100], search, start_element, number;
printf ("Enter number of elements in array\n");
scanf ("%d", &number);
printf ("Enter %d integer(s)\n", number);
for (start_element = 0; start_element < number; start_element++)
scanf ("%d", &array[start_element]);// for taking numbers from users
printf ("Enter a number to search\n");
scanf ("%d", &search); // which number want to search
for (start_element = 0; start_element < number; start_element++) // checking number one by for search
{
if (array[start_element] == search) /* If required element is found */
{
printf ("%d is present at location %d.\n", search, start_element + 1);
break;
}
}
if (start_element == number)
printf ("%d isn't present in the array.\n", search);
return 0;
}