You are on page 1of 1

def linear_search(arr,x):

for i in range(len(arr)):
if arr[i]==x:
return i
return -1
n=int(input("enter the number of elementsin an array:"))
arr=[]
for i in range(0,n):
b=int(input("element"))
arr.append(b)
print(arr)
x=int(input("enter the searching element"))
result=linear_search(arr,x)
if result!=-1:
print("element is present at index:",str(result))
else:
print("element is not present in an array")

You might also like