How to calculate mode for Continuous series in C programming?

By | October 27, 2021

Calculate Mode for Continuous Series in C

// Here, ll = lowerLimit
// cl = classLength
// nc = number of classes
// sf = sum of frequency
// f = frequency
#include<stdio.h>
#include<conio.h>
int i,j,ll,up,cl,nc,l[100],u[100],f[100],temp,x[100],sort[100],tempsort;
float xl,fm,f1,f2;
void continous()
{
printf("Enter the lower limit: ");
scanf("%d",&ll);
printf("Enter the class length: ");
scanf("%d",&cl);
printf("Enter the total number of class: ");
scanf("%d",&nc);
for(i=0;i<nc;i++)
{
up=ll+cl;
l[i]=ll;
u[i]=up;
ll=up;
x[i]=((float)l[i]+(float)u[i])/2;
}
for(i=0;i<nc;i++)
{
printf("Enter the frequency for class %d-%d: ",l[i],u[i]);
scanf("%d",&f[i]);
sort[i]=f[i];
}
for(i = 0; i < nc-1; i++)
{
for(j = i + 1; j < nc ;j++)
{
if(sort[i] > sort[j])
{
//Exchange them
tempsort = sort[i];
sort[i] =sort[j];
sort[j] = tempsort;
}
}
}
//for(i=0;i<nc;i++)
// printf("%d ",sort[i]);

for(i=0;i<nc;i++)
{
if(sort[nc-1]==f[i])
{
temp=i;
}
}
for(i=0;i<nc;i++)
printf("%d-%d %d \n",l[i],u[i],f[i]);
printf(" ");
xl=(float)l[temp];
fm=(float)f[temp];
f1=(float)f[temp-1];
f2=(float)f[temp+1];
printf(" Xl:%d\n",(int)xl);
printf(" fm:%d\n",(int)fm);
printf(" f1:%d\n",(int)f1);
printf(" f2:%d\n",(int)f2);
printf(" c:%d\n",cl);
printf(" %.4f",xl+(((fm-f1)/((2*fm)-f1-f2))*cl));
}
void main()
{
clrscr();
continous();
getch();
}

Output:

How to calculate mode for Continuous series in C programming?