Program to find the element in an array with maximum occurrences
This is the program to find the element with maximum occurrences in an array.I extended the previous post program to get the element with maximum occurrences.
#include<stdio.h>
#include<conio.h>
int main()
{
int k=0,count=0,z=0;
int index;
int countarr[16],nos[16];
int arr[20]={1,1,23,23,23,34,34,34,45,45,33,33,33,33,33,33,54,54,11,12};
for(int i=0;i<20;i++)
{
if(i>0)
{
i=i+count-1;
}
nos[z]=arr[i];
z=z+1;
count=0;
for(int j=0;j<20;j++)
{
if(arr[i]==arr[j])
count++;
}
countarr[k]=count;
k=k+1;
}
int max=countarr[0];
for(int i=1;i<k;i++)
{
if(countarr[i]>max)
{
max=countarr[i];
index=i;
}
}
printf("The element which have maximum frequency is :\n");
printf("%d",nos[index]);
getch();
}
Comments
Post a Comment