Find the Second Largest Number in an Array

Let’s discuss a problem to find the second largest number in an array.

Given an unsorted array of integers, write a code to find the second largest number in an array.

For example –

Input – arr[] = { 4, 1, 5, 2, 8, 0, 3, 55}

Output – 8

The second max element in this array is 8.

Before checking the solution, let’s think for a moment, how do you approach this problem?  There are multiple ways to solve this problem. Which approach you prefer and why? At the end of this tutorial, I have shared the link to the video tutorial.

In this tutorial, I am going to cover following topics –

  • How to find the second largest number in an array using sorting.
  • C program to find the second largest number in an array.
  • C++ program to find the second largest number in an array.

Print Prime Numbers from 1 to N | Sieve of Eratosthenes

Write a program to print prime numbers from 1 to N (where n is an integer).

This problem can also be asked like,

i) How to print prime numbers from 1 to 100.

ii) How to print prime numbers from 1 to 1000 etc.

In this tutorial, we are going to learn how to print prime numbers efficiently using sieve algorithm.

Suppose the value of N is 10, So the prime numbers between 1 to 10 is 2, 3, 5, 7.

Before writing a code, let’s first first understand, what is prime number?