-
Notifications
You must be signed in to change notification settings - Fork 28
/
arraySearch.c
41 lines (30 loc) · 753 Bytes
/
arraySearch.c
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
/*********
Author1 Name:
Author2 Name:
FIXED THE BUGS FOR GIT-WORKSHOP
**********/
#include<stdio.h>
int main() {
int a[30], ele, num, i;
printf("\nEnter no of elements :");
scanf("%d", &num);
printf("\nEnter the values :");
for (i = 0; i < num; i++) {
scanf("%d", &a[i]);
}
//Read the element to be searched
printf("\nEnter the elements to be searched :");
scanf("%d", &ele);
// HERE IS THE BUG, WE MISSED THE FIRST ELEMENT OF THE ARRAY. CHANGE i=1 to i=0
i = 1;
while (i < num && ele != a[i]) {
i++;
}
//If i < num then Match found
if (i < num) {
printf("Number found at the location = %d", i + 1);
} else {
printf("Number not found");
}
return (0);
}