Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void getMode(int count, int &i, int &save,int &index) {
- if (count > save) {
- save = count;
- index = i;
- }
- }
- int getOccurrence(int arr[], int size) {
- int count(0); int save(0); int index = 0;
- for (int i = 0; i < size; i++) {
- for (int j = 0; j < size; j++) {
- if (arr[i] == arr[j])
- count++;
- }
- getMode(count, i,save,index);
- count = 0;
- }
- return index;
- }
- int main() {
- int size; int array[100], mode(0);
- cout << "Enter the size of the array\n";
- cin >> size;
- cout << "Enter your array\n";
- for (int i = 0; i < size; i++) {
- cin >> array[i];
- }
- mode= getOccurrence(array, size);
- cout << "The mode of your array is " << array[mode] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement