Computer Science, asked by Darshananand6426, 9 months ago

Write a C++ program to find the most occurring element in an array of integers.

Answers

Answered by parirupesushila
7

it's just simple

------------------------------------------------

here we go

------------------------------------------------

#include<iostream.h>

#include<conio.h>

{

int max_count = 0;

cout << "\nMost occurred number: ";

for (int i=0; i<size; i++)

{

int count=1;

for (int j=i+1;j<size;j++)

if (nums[i]==nums[j])

count++;

if (count>max_count)

max_count = count;

}

for (int i=0;i<size;i++)

{

int count=1;

for (int j=i+1;j<size;j++)

if (nums[i]==nums[j])

count++;

if (count==max_count)

cout << nums[i] << endl;

}

}

int main()

{

int nums[] = {4, 5, 9, 12, 9, 22, 45, 7};

int n = sizeof(nums)/sizeof(nums[0]);

cout << "Original array: ";

for (int i=0; i < n; i++)

cout << nums[i] <<" ";

most_occurred_number(nums, n);

}

Similar questions