# How to Calculate Median for Continuous Series in C programming?

By | October 23, 2021

Calculate Median for Continuous Series in C programming

```// Here, ll = lowerLimit
// cl = classLength
// nc = number of classes
// sf = sum of frequency
// cf = commulative frequency
// f = frequency
#include<stdio.h>
#include<conio.h>
int i,j,ll,up,cl,nc,l[100],u[100],f[100],sf,am,cf[100],temp,x[100];
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]);
}
cf[0]=f[0];
for(i=0;i<nc;i++)
{
cf[i+1]=cf[i]+f[i+1];
}
for(i=0;i<nc;i++)
sf+=f[i];
for(i=0;i<nc;i++) { if((sf/2) >= cf[i])
temp=i+1;
}
printf("Class Freq C.F. ");
i=0;
for(i=0;i<25;i++)
printf("-");
for(i=0;i<nc;i++)
printf(" %d-%d  %d %d ",l[i],u[i],f[i],cf[i]);
for(i=0;i<25;i++)
printf("-");
printf(" Total %d ",sf);
printf(" Xl:%d N/2:%.2f F<:%d f:%d c:%d",l[temp],((float)sf/(float)2),cf[temp-1],f[temp],cl);
printf(" The median is: %.4f",l[temp]+(((((float)sf/(float)2) - cf[temp-1] )/f[temp])*cl));
}
void main()
{
clrscr();
continous();
getch();
}
```

Output:

## One thought on “How to Calculate Median for Continuous Series in C programming?”

1. Kevin Hesketh

Nice post. I was checking constantly this blog and
I’m impressed!
Very useful information particularly the last part
I care for
such information much. I was seeking this certain info for
a long time. Thank you and best of luck.