Find Common Elements in Two Arrays – Intersection of two Arrays

Write a c program to find common elements in two arrays.

Given two positive integer arrays arr1 and arr2 of lengths len1 and len2. We have to write a c code to find intersection of these two arrays. Both the arrays are sorted.

Let’s assume we have following two sorted arrays arr1 and arr2.

int arr1[] = {2,  3,  4,  5,  6};
int arr2[] = {4,  6,  7,  8,  9};

So the common elements in these two arrays is 4 and 6.

Find Common Elements in Two Arrays

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.