How do you find the largest and smallest number in an unsorted integer array? on Python

Q#3


Hi friends
Welcome, we solve question number 2, here coding to solve another question.


Question 2:
       How do you find the largest and smallest number in an unsorted integer array? 


We need input from user for array. But don't worry about it. Here Python code also do it for us randomly in every time.
Let's Code and Check...


CODE:

import random
a = []
while len(a) < 10:
  ranAdd = random.randint(1,100)
  a.append(ranAdd)

print('Given Arrray: \n',a,'Total count: ',len(a))
max = a[0]
min = a[0]
for i in a:
  if max < i:
    max = i
  
  if min > i:
    min = i

print('Maximum number from given array: ',max)
print('Minimum number from given array: ',min)


----

By
PyKAR

Comments

Popular posts from this blog

Hardy - Ramanujan Number (Magic Number) Program in Python

FLAMES CODE ON PYTHON

Count Swap for Sorting in Python