/* 5 PROGRAM TO CALCULATE MEDIAN FOR DISCRETE SERIES*/
#include<stdio.h>
int main()
{
int x[]={1,2,3,4,5,6,7,8,9};
int f[]={8,10,11,16,20,25,15,9,6};
int i,cf[10],l,s,n=0;
printf("\nCOMPUTATION OF MEDIAN");
cf[0]=f[0];
for(i=0;i<9;i++)
{
cf[i+1]=f[i+1]+cf[i];/* The Addition of cumulative frequency */
n=n+f[i];
}
n=n/2; /* Calculation of n/2 */
for(i=0;i<9;i++)
{
if(n>cf[i])/* Calculation of cumulative C.F.*/
{
l=i;
s=cf[i+1];
}
}
printf("\n\n\tX\tFREQUENCY\tC.F.\n\n");
for(i=0;i<9;i++)
printf("\n\t%d\t%d\t\t%d",x[i],f[i],cf[i]);
printf("\n The calculation of n/2 is:-%d",n);
printf("\n The Cumulative Frequency is:-%d",s);
printf("\n Cumulative Frequency is greater than %d is %d",n,s);
printf("\n The value of X corresponding to %d is %d", s,x[l+1]);
return 0;
}
/* OUTPUT
COMPUTATION OF MEDIAN
X FREQUENCY C.F.
1 8 8
2 10 18
3 11 29
4 16 45
5 20 65
6 25 90
7 15 105
8 9 114
9 6 120
The calculation of n/2 is:-60
The Cumulative Frequency is:-65
Cumulative Frequency is greater than 60 is 65
The value of X corresponding to 65 is 5 */
No comments:
Post a Comment
This Blog helps you to learn basics to high level programming coding and practicals.
conceptual understanding