top of page
Writer's pictureJino Shaji

Program to find the Mean,Median,Mode,Variance and Standard Deviation

Updated: Jun 9, 2020


Program to find the Mean,Median,Mode,Variance and Standard Deviation


#include
#include
#include
#define SIZE 100
void main()
{
 long int x[SIZE],x2[SIZE],sum_of_x=0,sum_of_x2=0,i,j,n,s,temp;
 double SD,variance,AM,MEDI,MOD;
 clrscr();
 printf(“Enter The Number Of Observations\n\n”);
 scanf(“%ld”,&n);
 printf(“Enter the Observations\n”);
 for(i=0;i<n;i++)
 {
  scanf(“%ld”,&x[i]);
  sum_of_x+=x[i];
  x2[i]=x[i]*x[i];
  sum_of_x2+=x2[i];
 }
 for(i=1;i<n-1;i++)
 {
  for(j=0;j<n-1;j++)
 {
  if(x[j]>x[i])
 {
  temp=x[i];
  x[i]=x[j];
  x[j]=temp;
 }
  }
 }
  AM=sum_of_x/n;
  s=(n+1)/2;
  if((n+1)%2!=0)
 {
  MEDI=(x[s-1]+x[s])/2;
  }
 else
  {
  MEDI=x[s-1];
  }
  MOD=(3*MEDI)-(2*AM);
  SD=sqrt((sum_of_x2/n)-pow(AM,2));
  variance=pow(SD,2);
  printf(“\n\n\t\tTABLE OF CALCULATION\n\n”);
  printf(“\tX\tX2\n\n”);
  printf(“……………………………………………………\n”);
  for(i=0;i<n;i++)
 printf(“\t%ld\t%ld\n”,x[i],x2[i]);
 printf(“\n MEAN : %2.3lf  MEDIAN  :  %.2lf  MODE  : %.2lf SD: %.3lf VARIANCE : %.3lf\n”,AM,MEDI,MOD,SD,variance);
getch();
}

Output


8 views0 comments

Recent Posts

See All

Pointers In C

C Pointers Pointers in C are easy and fun to learn. Some C programming tasks are performed more easily with pointers, and other tasks,...

Commenti


bottom of page