Tuesday, April 3, 2012

Program to find the Average and Standard deviation of N given numbers


#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<<"Program to find Mean and Standard deviation\n";
cout<<"ENTER  MAXIUM NUMBER OF TERMS "<< 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>***************/


Output of this program is:



No comments:

Post a Comment