1//copied from GeeksForGeeks
2#include <bits/stdc++.h>
3using namespace std;
4
5// Function that sort input array a[] and
6// calculate mode and median using counting
7// sort.
8void printMode(int a[], int n)
9{
10 int b[n];
11 int max = *max_element(a, a + n);
12 int t = max + 1;
13 int count[t];
14 for (int i = 0; i < t; i++)
15 count[i] = 0;
16 for (int i = 0; i < n; i++)
17 count[a[i]]++;
18 int mode = 0;
19 int k = count[0];
20 for (int i = 1; i < t; i++) {
21 if (count[i] > k) {
22 k = count[i];
23 mode = i;
24 }
25 }
26
27 cout << "mode = " << mode;
28}
29//Just Include this in your template and call the function printMode
30//to print the mode