Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Solution to Question No.

3 :
Program:
* Program to accept a discrete 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],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 classes(less than or equal to 50):");
scanf("%d",&n);
while(n < 1)
{
printf("Number of classes must be an integer greater than or
equal to 1.\nEnter the number of classes :");
}
if( n > 50)
{
printf("Number of classes is out of range\n");
}
for( i = 0 ; i < n ; i++)
{
printf("Enter the class no. %d :",i+1);
scanf("%lf",&value[i]);
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 < 4 ; i++)
{
sum[i] = 0;

}
for( i = 0; i < 4 ; i++)
{
for( j = 0; j < n ; j++)
{
sum[i] = 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 no. %d Value : %lf Frequency : %d
\n",i+1,value[i],freq[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