Documente Academic
Documente Profesional
Documente Cultură
com)
C Programming Examples
Java Algorithms
C++ Algorithms
C Algorithms
Problem Description
The program takes a list and prints the second largest number in the list.
Problem Solution
1. Take in the number of elements and store it in a variable.
2. Take in the elements of the list one by one.
3. Sort the list in ascending order.
4. Print the second last element of the list.
5. Exit.
Program/Source Code
Here is source code of the Python Program to find the second largest number in a list. The program output is also shown below.
a=[]
n=int(input("Enter number of elements:"))
for i in range(1,n+1):
b=int(input("Enter element:"))
a.append(b)
a.sort()
print("Second largest element is:",a[n-2])
Program Explanation
1. User must enter the number of elements and store it in a variable.
2. User must then enter the elements of the list one by one using a for loop and store it in a list.
3. The list should then be sorted.
4. Then the last element of the list is printed which is also the largest element of the list.
Case 1:
Enter number of elements:4
Enter element:23
Enter element:56
Enter element:39
Enter element:11
Second largest element is: 39
Case 2:
Enter number of elements:3
Enter element:23
Enter element:4
Enter element:67
Second largest element is: 23
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions (http://www.sanfoundry.com/python-problems-solutions/).
Prev Page - Python Program to Find the Largest Number in a List (http://www.sanfoundry.com/python-program-find-largest-number-list/)
Next Page - Python Program to Find the Union of two Lists (http://www.sanfoundry.com/python-program-find-union-two-lists/)
Deep Dive @ Sanfoundry:
1. C Programming Examples on Searching and Sorting (http://www.sanfoundry.com/c-programming-examples-searching-sorting/)
2. C++ Programming Examples on Combinatorial Problems & Algorithms (http://www.sanfoundry.com/cpp-programming-examples-combinatorial-
problems-algorithms/)
3. Java Programming Examples on Combinatorial Problems & Algorithms (http://www.sanfoundry.com/java-programming-examples-combinatorial-
problems-algorithms/)
4. C# Programming Examples on Matrix (http://www.sanfoundry.com/csharp-programming-examples-on-matrix/)
5. C Programming Examples on Combinatorial Problems & Algorithms (http://www.sanfoundry.com/c-programming-examples-combinatorial-problems-
algorithms/)
6. C# Programming Examples on Arrays (http://www.sanfoundry.com/csharp-programming-examples-on-arrays/)
7. C Programming Examples on Linked List (http://www.sanfoundry.com/c-programming-examples-linked-list/)
8. C Programming Examples on Arrays (http://www.sanfoundry.com/c-programming-examples-arrays/)
9. C# Programming Examples on Sorting (http://www.sanfoundry.com/csharp-programming-examples-on-sorting/)
10. Python Programming Examples (http://www.sanfoundry.com/python-problems-solutions/)
.
DO YOU KNOW YOUR TECH ODDS AND ENDS?
A 45%
B 92%
C 25%
Manish Bhojasia (http://www.sanfoundry.com/about/), a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at
Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in
Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux
Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage
Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn (http://www.linkedin.com/in/manishbhojasia) | Facebook (http://www.facebook.com/sanfoundry) | Twitter
(http://www.twitter.com/sanfoundry) | Google+ (https://plus.google.com/104408026570656234343/posts)
Name*
Email*
Subscribe
Best Careers
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in
India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro,
Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.
Best Trainings
India Internships
About Sanfoundry
About Us (http://www.sanfoundry.com/about/)
Copyright (http://www.sanfoundry.com/copyright/)
TOS & Privacy (http://www.sanfoundry.com/tos-privacy-policy/)
Jobs (http://www.sanfoundry.com/jobs/)
Bangalore Training (http://www.sanfoundry.com/coursesfees/)
Online Training (http://www.sanfoundry.com/online-training-san-linux-kernel-device-drivers/)
SAN Training (http://www.sanfoundry.com/san-storage-area-networks-training/)
Developers Track (http://www.sanfoundry.com/salary-50l/)
Mentoring Sessions (http://www.sanfoundry.com/professional-mentoring-coaching-career-guidance-cto/)
Contact Us (http://www.sanfoundry.com/contact/)
Sitemap (http://www.sanfoundry.com/sitemap_index.xml)
2011-2017 Sanfoundry