Write a program to accept 10 different numbers in a single dimensional array . Search for a given number using linear search technique
Answers
Answered by
4
def linear_search(arr, n):
for idx, item in enumerate(arr):
if n == item:
return idx
return -1
nums = [int(n) for n in input("enter 10 nums: ").split()]
n = int(input("enter num to search: "))
idx = linear_search(nums, n)
if idx > -1:
print(f"item found at idx: {idx}")
else:
print("item not found")
Similar questions
Biology,
2 months ago
Math,
2 months ago
Math,
2 months ago
Science,
5 months ago
English,
5 months ago
Accountancy,
11 months ago
Accountancy,
11 months ago