Create Linear search.py

pull/343/head
Kavin18 2024-05-16 17:03:52 +05:30 zatwierdzone przez GitHub
rodzic 33d752647f
commit 5421e75588
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 18 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,18 @@
def search(arr, N, x):
for i in range(0, N):
if (arr[i] == x):
return i
return -1
if __name__ == "__main__":
arr = list(map(int,input("enter the array elements: ").split()))
x = int(input("enter the number to search: "))
N = len(arr)
result = search(arr, N, x)
if(result == -1):
print("Element is not present in array")
else:
print("Element is present at index", result)