Skip to content

Commit be822a5

Browse files
author
d4az
authored
Add files via upload
1 parent 06955a8 commit be822a5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Linear Search Simplified/file.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <stdio.h>
2+
#include <stdbool.h>
3+
#define size 5
4+
5+
6+
int linearsearch(int data[] , int sk)
7+
{
8+
int anw;
9+
bool flag = false;
10+
11+
for(int i = 0 ; i < size ; i++){
12+
13+
if(data[i] == sk){
14+
anw = i;
15+
flag = true;
16+
break;
17+
}
18+
19+
}
20+
21+
if(flag == false){
22+
return -1;
23+
}else{
24+
return anw;
25+
}
26+
}
27+
28+
29+
int main(void){
30+
int data[size] = {5,4,3,8,1};
31+
int sk;
32+
printf("enter the search key : ");
33+
scanf("%d",&sk);
34+
35+
int out = linearsearch(data ,sk);
36+
37+
if(out != -1){
38+
printf("value found -> %d", out);
39+
}else{
40+
printf("not found!");
41+
}
42+
}

0 commit comments

Comments
 (0)