A = [45, 17, 28, 34, 100] i = 0 nmin = i min = a[nmin] nmax = i max = a[nmax] while (i < len(a)): if (a[i] < min): nmin = i min = a[nmin] if (a[i] > max): nmax = i max = a[nmax] i += 1 print "min = a[", nmin, "] = ", min print "max = a[", nmax, "] = ", max
N = 10
a = []
for i in range(N):
b = int(random() * 50)
a.append(b)
print(a)
min = a[0]
max = a[0]
for i in range(N):
if (a[i] < min):
min = a[i] if a[i]>max:
max = a[i]print('min = ',min)
print('max = ',max)
Пример:
[48, 12, 44, 48, 32, 1, 10, 37, 42, 21]
min = 1
max = 48
i = 0
nmin = i
min = a[nmin]
nmax = i
max = a[nmax]
while (i < len(a)):
if (a[i] < min):
nmin = i
min = a[nmin]
if (a[i] > max):
nmax = i
max = a[nmax]
i += 1
print "min = a[", nmin, "] = ", min
print "max = a[", nmax, "] = ", max