Chapter 11: Pointers

Example maxmin.c, Page 250

In [4]:
N=10
def max_min(a,n): #function definition
    max=a[0]
    min=a[0]
    for i in range(n-1): #calculating max and min from list
        if(a[i+1]>max):
            max=a[i+1]
        elif(a[i+1]<min):
            min=a[i+1]
    return (max,min)
li=raw_input("Enter %d numbers: " % N) #input of numbers from user
b=map(int, li.split())
big,small=max_min(b,N) #call function to calculate max and min
print "Largest: %d"%big #print max and min
print "Smallest: %d"%small
Enter 10 numbers: 34 82 49 102 7 94 23 11 50 31
Largest: 102
Smallest: 7
In [ ]: