Find the two largest numbers in an array

Find two largest elements array

Given an array of positive integers. Find the first and second largest elements in the array.

Largest two numbers in an array solution

One solution is to use two loops. The first loop finds the first maximum and the second loop finds the second maximum. Note that the second loop needs to exclude the first maximum. In the next post we will solve this problem using only a single loop.

Code

Here is a c program to print largest two numbers using two loops

Please use the comments section below for questions or feedback. Thanks for visiting.

Tags:

Add a Comment

Your email address will not be published. Required fields are marked *