Answer:
This question is answered using Python programming language
def MaxSet(mylist, count):
if (count == 1):
return mylist[0]
return max(mylist[count - 1], MaxSet(mylist, count - 1))
def MinSet(mylist, count):
if (count == 1):
return mylist[0]
return min(mylist[count - 1], MinSet(mylist, count - 1))
count = int(input("Length of set: "))
mylist = []
for i in range(count):
inp= int(input("Input: "))
mylist.append(inp)
print("Minimum: "+str(MinSet(mylist, count)) )
print("Maximum: "+str(MaxSet(mylist, count)) )
Step-by-step explanation:
This defines the recursion that returns the maximum
def MaxSet(mylist, count):
This following checks for the maximum using recursion
if (count == 1):
return mylist[0]
return max(mylist[count - 1], MaxSet(mylist, count - 1))
This defines the recursion that returns the minimum
def MinSet(mylist, count):
This following checks for the minimum using recursion
if (count == 1):
return mylist[0]
return min(mylist[count - 1], MinSet(mylist, count - 1))
The main begins here
This prompts user for length of set
count = int(input("Length of set: "))
This defines an empty list
mylist = []
The following iteration gets user input
for i in range(count):
inp= int(input("Input: "))
mylist.append(inp)
This calls the minimum function
print("Minimum: "+str(MinSet(mylist, count)) )
This calls the maximum function
print("Maximum: "+str(MaxSet(mylist, count)) )