Monday, March 26, 2012

Program to find mean and standard deviation in c++

/****************<soeasyprograms.blogspot.in>**********************/
#include <math.h>
#include <iostream.h>
#include <conio.h>

#define MAX 10

main()
{
float x = 0, sd, s = 0, m, sum = 0;
int n, i, d, a[MAX];
clrscr();
cout<<"Enter How many inputs you have to calculate SD [MAX ]: "<< MAX<<endl;
cin>>n;
if ( n > MAX ){
cout<<"Sorry your input limit is greater than Max value"<< MAX;

}
for (i = 0; i < n; i++){
cout<<"Enter the Integer elements "<<i+1<<" of "<< n<<":";
cin>>a[i];
}
for(i=0; i < n; i++){
x = x + a[i];
}
m=x/n;
for (i =0; i < n; i++){//calculating sd
d = a[i] - m;
sum += d * d;
}
s = sum / n;
sd = sqrt(s);//standard deviation
cout<<"the number of input terms ="<< n;
cout<<"\nMean = " <<m;
cout<<"\nStandard Deviation ="<<sd;
cout<<"\nEXIT_SUCCESS";
getch();
}
/****************<soeasyprograms.blogspot.in>**********************/

No comments:

Post a Comment