0
Find largest and smallest element in given array
plz check following code.Getting largest element correctly, but something is wrong with smallest element. https://code.sololearn.com/c4YZs0BSItxP/?ref=app Plz help to solve this.
6 odpowiedzi
+ 2
def largestSmallest(A):
max=A[0]
min=A[0]
for i in A:
if i >max:
max=i
if i < min:
min=i
print ("largest element is",max)
print ("smallest element is",min)
A=[45,12,3,5,100]
largestSmallest(A)
0
Why don't use max() and min() functions ?
0
don't want to use library functions.
0
If you set min=0 it will be hard to change it 😉 If you don't use lists then set min as 100 and change elif i>min: to elif i<min:
0
@Raziul Islam
thank you ... it works...
0
welcome