Commit 0165a42
committed
feat: Search for an element in an array using linear search
🧠 Logic:
- Takes the size of the array and its elements from the user.
- Prints all array elements.
- Asks the user for an element to search (`s`) in the array.
- Uses a linear search (`for` loop) to check each element:
- If match is found, sets `x = 1` and stores the index in `pos`, then breaks the loop.
- After search:
- If `x == 0`, element was not found.
- If `x == 1`, displays the index where the element was found.
Signed-off-by: Somesh diwan <[email protected]>1 parent eb48782 commit 0165a42
1 file changed
+4
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
15 | | - | |
16 | 18 | | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
0 commit comments