Write a program for linear search


Write a program for a linear search.


  1. def linersearch(search,list):
        flag=0
        for item in list:
            if search==item:
              flag=1
              break
        if flag==1:
            print("value exist.")
        else:
            print("value does not exist.")
    elements=[]
    num_of_elmenets=int(input("how many elment you want to Enter: "))
    for i in range(num_of_elmenets):
        elm=int(input("Enter element "))
        elements.append(elm)
    ser=int(input("enter the value to search: "))
    linersearch(ser,elements)


Output:-



Post a Comment

0 Comments