Computer Science, asked by TeeshaAhuja, 9 months ago

Write a program to find the largest and the second

largest elements in a given list of elements​

Answers

Answered by sandhyanaidu44418
5

Answer:

Input : list1 = [10, 20, 4]

Output : 10

Input : list2 = [70, 11, 20, 4, 100]

Output : 70

Explanation:

Answered by Equestriadash
24

The following codes are written in Python.

Source code:

c = input("Enter the data type you want to add into the list: ")

if c == "string" or c == "String":

 n = int(input("Enter the number of elements you'd like to enter: "))

 sl = list()

 for i in range(n):

   x = input("Enter the element: ")

   sl.append(x)

 print(sl, "is your given list.")

 sl.sort()

 print(sl[-1], "and", sl[-2], "are the largest and second largest elements in the given list.")

elif c == "integer" or c == "Integer":

   n = int(input("Enter the number of elements you'd like to enter: "))

   il = list()

   for i in range(n):

       x = int(input("Enter the element: "))

       il.append(x)

   print(il, "is your given list.")

   il.sort()

   print(il[-1], "and", il[-2], "are the largest and second largest elements in the given list.")

Similar questions