forked from akn714/1st-yr-c-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
24.c
40 lines (32 loc) · 813 Bytes
/
24.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
// Task : WAP to search an element in an array using Linear Search
#include <stdio.h>
#include <stdbool.h>
int main() {
int n, i;
// inputtting the size of array
printf("size of array? ");
scanf("%d", &n);
int arr[n];
// inputting the array elements
printf("enter elements of the array : ");
for(i=0;i<n;i++){
scanf("%d", &arr[i]);
}
printf("which element do you want to find : ");
int toFind;
scanf("%d", &toFind);
bool isFound = false;
for(i=0;i<n;i++){
if(toFind==arr[i]){
isFound = true;
break;
}
}
if(isFound){
printf("%d found on index %d\n", toFind, i);
}
else{
printf("%d doesn't exist in the given array!\n", toFind);
}
return 0;
}