Ml

                Never    
C++
       
#include<iostream.h>
#include<conio.h>
#include<math.h>


float variance(float tage,int n){
  float var= tage/(n-1);
  return var;

}
//------------------------------------------
float stvar(float var){
return sqrt(var);

}
//----------------------------------------------
float med(int n,int *age){
 float total=0;
 if(n%2==0){
   total=age[n/2]+age[(n/2)-1];
 }
 else{
  int v=n/2;
  total=age[v+1];
  return total;
 }
 return total/2;
}
//----------------------------------------------
void sort(int *age,int n){
int t;
 for(int i=0;i<n;i++){
   for(int j=0;j<n;j++){
     if(age[i]>age[j]){
     t=age[i];
     age[i]=age[j];
     age[j]=t;
     }
   }
 }
}
//--------------------------------------
void agebar(int *age,float *ageb,float *agebs,float m,int n){
 for(int i=0;i<n;i++){
  ageb[i]=age[i]-m;
  agebs[i]=ageb[i]*ageb[i];

 }
}
//----------------------
float tabs(float *agebs,int n){
float t=0;
for(int i=0;i<n;i++)
 t+=agebs[i];
 return t;
}

int main(void){
clrscr();
int n;
float a;

int *age=new int[n];
float *ageb=new float[n];
float *agebs=new float[n];
cout<<"Enter the Number of Ages: ";
cin>>n;

for(int i=0;i<n;i++){
cout<<"Enter the "<<i+1<<" age: ";
cin>>age[i];
}

sort(age,n);
float m=med(n,age);
cout<<"the median is : "<<m<<endl<<endl;
agebar(age,ageb,agebs,m,n);
float tagebs=tabs(agebs,n);
cout<<"total: "<<tagebs<<endl;
cout<<"\t"<<"age"<<"\t"<<"(age-ageb)"<<"\t"<<"s(age-age)\n\n";
for(i=0;i<n;i++){
cout<<"\t"<<age[i]<<"\t"<<ageb[i]<<"\t\t"<<agebs[i]<<endl;
}

float var=variance(tagebs,n);
cout<<"the variance is : "<<var<<endl;
float std=stvar(var);
cout<<"and the st dev is "<<std<<endl;
getch();


return 0;
}

Raw Text