#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int maximum(int *arr, int n)
{
int max = INT_MIN;
for (int i = 0; i < n; i++)
{
if (arr[i] > max)
{
max = arr[i];
}
}
return max;
}
int maximumandindex(int *arr, int n)
{
int max = INT_MIN;
int index;
for (int i = 0; i < n; i++)
{
if (arr[i] > max)
{
max = arr[i];
index = i;
}
}
return index;
}
void duplicateandrepeating(int *arr, int n)
{
int max = maximum(arr, n);
int *duparr = (int *)calloc(max, sizeof(int));
for (int i = 0; i < n; i++)
{
duparr[arr[i]]++;
}
for (int i = 0; i <= max; i++)
{
if (duparr[i] > 1)
{
printf("%d and %d\n", i, duparr[i]);
}
}
printf("most repeating element : %d and %d", maximumandindex(duparr, max+1), maximum(duparr, max+1));
}
int main()
{
clock_t t;
t = clock();
int n;
printf("enter the size of array : ");
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
duplicateandrepeating(arr, n);
t = clock() - t;
double time_taken = ((double)t) / CLOCKS_PER_SEC;
printf("\nfun() took %f seconds to execute \n", time_taken);
return 0;
}