NEP -PYTHON

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8

PART B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

 
   
#6. Implement A Sequential Search
-------------------------
def LinearSearch(array, n, k):
    for j in range(0, n):
        if (array[j] == k):
            return j
    return -1

array = [1, 3, 5, 7, 9]

#print(array)
k =int( input("enter a number to search: "))
n = len(array)

result = LinearSearch(array, n, k)

if(result == -1):
    print("Element not found")
else:
    print("Element found at index: ", result)

OUTPUT
----------------------------------
enter a number to search: 20
Element not found

enter a number to search: 5
Element found at index:  2