C++ PROGRUM 03 FOR MECHANICAL

3. Calculate the mean, variance, skewness and  kurtosis of the data. ( WHILE Statement)
1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 7, 8, 8, 10

#include <stdio.h>
main()
{
 int n, count;
 float x, s1, s2, s3, s4, mean, c2, c3, c4, b1, b2, r1, r2, r3, r4;
 printf("Enter the value of n\n");
 scanf("%d", &n);
 s1 = 0.0;
 s2 = 0.0;
 s3 = 0.0;
 s4 = 0.0;
 count = 1;
 printf("Enter the values of x\n");
 while(count <= n)
 { 
   scanf("%f", &x);
   s1 = s1 + x;
   s2 = s2 + x*x;
   s3 = s3 + x*x*x;
   s4 = s4 + x*x*x*x;
   count++;
 }
   printf(" Sum of x = %f\n", s1);
   printf(" Sum of x^2 = %f\n", s2);
   printf(" Sum of x^3 = %f\n", s3);
   printf(" Sum of x^4 = %f\n", s4);
 /* Finding raw moments about origin */
  mean = s1/n;
 r1 = s1/n;
 r2 = s2/n;
 r3 = s3/n;
 r4 = s4/n;
 printf(" 1st raw moment about origin = %f\n", r1);
 printf(" 2nd raw moment about origin = %f\n", r2);
 printf(" 3rd raw moment about origin = %f\n", r3);
 printf(" 4th raw moment about origin = %f\n", r4);
 /* Finding central moment */
 c2 = r2-(r1*r1);
 c3 = r3-3*r2*r1+2*r1*r1;
 c4 = r4-4*r3*r1+6*r2*r1*r1-3*r1*r1*r1*r1;
 printf(" 2nd central moment = %f\n", c2);
 printf(" 3rd central moment = %f\n", c3);
 printf(" 4th central moment = %f\n", c4);
 /* Finding skewness and kurtosis */
 b1 = (c3*c3)/(c2*c2*c2);
 b2 = c4/c2*c2;
 printf(" Results of findings\n");
 printf("Mean = %f\n", mean);
 printf("Variance = %f\n", c2);
 printf("Skewness = %f\n", b1);
 printf("Kurtosis = %f\n", b2);
 return 0;
}

Comments

Popular posts from this blog

Industrial Attachment

লেনজ এর সুত্র