C Program to Find Mode
The mode is the value that appears most often in a set of data. The mode of a discrete probability distribution is the value x at which its probability mass function takes its maximum value. In other words, it is the value that is most likely to be sampled.
#include<stdio.h>
int arr[100],temp,i,j,n,k=0,count=0;
int mode[100];
main()
{
printf("Enter Array Elements n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
printf("Sorted Elements are n");
for(i=0;i<n;i++)
{
printf("%d t",arr[i]);
}
modefinder();
print();
}
int modefinder()
{
int min=0;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]==arr[j])
{
mode[k]=arr[i];
k++;
count++;
}
}
}
}
int print()
{
printf("count n %d",count);
if (count==0)
printf("nMode is 1n");
else
printf("nMode is %d",mode[k-1]);
}
Recent Comments