Introduction

Control Statement

- Program to find the sum of Natural Numbers using Recursion
- Calculator Program
- Program to identify day of week
- Program to print Fibonacci series
- Check Whether the Number is Even or Odd in C++
- Program to check whether the number is prime or not
- Program to check vowel or constant
- Program to check the largest number among three numbers
- Program to the sum of natural numbers

Function

- Program to find LCM
- Program to check prime number using Functions
- Program to convert Binary to Decimal Number
- Program to convert Decimal to Binary Number
- Program to convert Binary to Octal Number
- Program to convert Octal to Binary Number
- Program to find reverse of the sentence using Recursion
- Program to Shutdown and restart Computer
- Program to find the area of triangle

Array

Pointer

OOPS

No Examples found for this topic - CodeHelpPro

# Program to find the most repeated element from the array

In this example, We will find the most repeated number from the given array.

To understand this example, You must have knowledge in following topics

First we will take array as input and we will find all most ocuring element in array using c++ programming language.

Let’s look and code to make clear concepts

```
#include <iostream>
using namespace std;
void repeated_number(int arr[], int n){
int i, j, max_count = 0;
cout << "\nMost occurred number: ";
for (i = 0; i < n; i++)
{
int count = 1;
for (j = i + 1; j < n; j++)
if (arr[i] == arr[j])
count++;
if (count > max_count)
max_count = count;
}
// this loop checks if there are more than one elements that are repeated
for (i = 0; i < n; i++)
{
int count = 1;
for (j = i + 1; j < n; j++)
if (arr[i] == arr[j])
count++;
if (count == max_count)
cout << arr[i] << endl;
}
}
int main()
{
int arr[100], n, i;
cout << "Enter number of elements in array: ";
cin >> n;
cout << "\nEnter array elements: ";
for (i = 0; i < n; i++)
cin >> arr[i];
cout << "Original array: ";
for (i = 0; i < n; i++)
cout << arr[i] << " ";
repeated_number(arr, n);
return 0;
}
```

The output of above program is

```
Enter number of elements in array: 7
Enter array elements: 1
6
4
6
2
3
6
Original array: 1 6 4 6 2 3 6
Most occurred number: 6
```

Subscribe

Login

0 Comments

Inline Feedbacks

View all comments