Professional Documents
Culture Documents
Solution To Question No.2: Program
Solution To Question No.2: Program
2 :
Program:
/* Program to accept a number of observations from the user and calculate
their mean,variance and moment measures of 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 i,j,n;
clrscr();
printf("Enter the number of observations(less than or equal to
50):");
scanf("%d",&n);
while(n < 1)
{
printf("Number of observations must be an integer greater
than or equal to 1.\nEnter the number of observations :");
}
if( n > 50)
{
printf("Number of observations is out of range\n");
}
for( i = 0 ; i < n ; i++)
{
printf("Enter observation no. %d :",i+1);
scanf("%lf",&value[i]);
}
for( i = 0; i < 4 ;
{
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));
=
=
=
=
=
=
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 observations are :\n\n");
for( i = 0; i < n; i++)
{
printf("%lf ",value[i]);
}
printf("\n\nTotal number of observations : %d\nArithmetic Mean :
%lf\nStandard
Deviation : %lf\nVariance : %lf\ng1 is %lf\ng2 is
%lf\n",n,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();
}