You are on page 1of 3

Solution to Question No.

4 :
Program:
/* Program to accept a grouped frequency distribution as input and
calculate moment measures of central tendency, dispersion, skewness and
kurtosis */
#include<stdio.h>
#include<math.h>
void main()
{
double value[50],ll[50],ul[50],sum[4],rmoment[4],
cmoment[4],am,sd,b1,b2,g1,g2;
int freq[50],i,j,totfreq,n;
clrscr();
printf("Enter the number of class intervals(less than or equal to
50):");
scanf("%d",&n);
while(n < 1)
{
printf("Number of class intervals must be an integer greater
than or equal to 1.\nEnter the number of class intervals");
}
if( n > 50)
{
printf("Number of class intervals is out of range\n");
}
for( i = 0 ; i < n ; i++)
{
printf("Enter the class interval no. %d ( lower limit - upper
limit ):",i+1);
scanf("%lf - %lf",&ll[i],&ul[i]);
value[i] = (ll[i] + ul[i])/2;
printf("Enter the frequency:");
scanf("%d",&freq[i]);
while(freq[i] < 0)
{
printf("Frequency must be non-negative\nEnter the
frequency:");
scanf("%d",&freq[i]);
}
}
totfreq = 0;
for( i = 0; i < n ; i++)
{
totfreq = freq[i] + totfreq;
}

for( i = 0; i < n ;
{
sum[i] = 0;
}
for( i = 0; i < 4 ;
{
for( j = 0; j
{
sum[i]
}
}

i++)

i++)
< n ; j++)
= sum[i]+(pow(value[j],i+1) * freq[j]);

for( i = 0; i < 4 ; i++)


{
rmoment[i] = sum[i]/totfreq;
}
cmoment[0] = 0;
cmoment[1] = rmoment[1] - pow(rmoment[0],2);
cmoment[2] = rmoment[2] - 3 * rmoment[1] * rmoment[0] + 2 *
pow(rmoment[0],3);
cmoment[3] = rmoment[3] - 4 * rmoment[2] * rmoment[0] + 6 *
rmoment[1] * pow(rmoment[0],2) - 3 * pow(rmoment[0],4);
am
sd
g1
b1
b2
g2

=
=
=
=
=
=

rmoment[0];
sqrt(cmoment[1]);
cmoment[2]/pow(sd,3);
pow(g1,2);
cmoment[3]/pow(cmoment[1],2);
b2 - 3;

clrscr();
printf("The given frequency distribution is :\n\n");
for( i = 0; i < n; i++)
{
printf("Class interval no. %d : %lf - %lf Frequency : %d
Class mark : %lf\n",i+1,ll[i],ul[i],freq[i],value[i]);
}
printf("\n\nTotal frequency : %d\nArithmetic Mean : %lf\nStandard
Deviation : %lf\nVariance : %lf\ng1 is %lf\ng2 is
%lf\n",totfreq,am,sd,cmoment[1],g1,g2);
if( g1 > 0)
{
printf("Distribution is positively skewed\n");
}
if( g1 < 0)
{
printf("Distribution is negatively skewed\n");
}
if( g1 == 0)
{
printf("Distribution is symmetrical\n");
}

if( g2 > 0)
{
printf("Distribution is leptokurtic\n");
}
if( g2 < 0)
{
printf("Distribution is platykurtic\n");
}
if( g2 == 0)
{
printf("Distribution is mesokurtic");
}
getch();
}

You might also like