Ex.No.: #4 FINDING MAXIMUM FROM A LIST OF NUMBERS (English)
Ex. No. :04 FINDING
MAXIMUM FROM A LIST OF NUMBERS
Program:
list=[] list=[2,52,6]
print("Enter the number of elements :")
n=int(input())
print("Enter the elements :")
for i in
range(0,n):
a = int(input())
list.append(a)
max=list[0]
for i in
range(len(list)):
if list[i]>max:
max=list[i]
print("Maximum number is :",max)
for
i in range(0,n):
a = int(input())
list.append(a)
2
|
52
|
6
|
list[0]
|
list[1]
|
list[2]
|
for i in
range(len(list)):
if list[i]>max:
max=list[i]
when i=0
if
list[0]>2
2>2 False
max=2
when i=1
if
list[1]>2
52>2 True
max=52
when i=2
if
list[2]>52
6>52 False
(max=52)
max=52
Output:
Enter the
number of elements :
3
Enter the
elements :
2
52
6
Maximum number
is : 52
Comments
Post a Comment