Write a program that takes as input five numbers and outputs

Write a program that takes as input five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x_1, x_2, x_3, x_4, and x_5, then the mean is x = (x_1, x_2, x_3, x_4, and x_5)/5 and the standard deviation is: S = Squareroot [(x_1 - x)^2 + (x_2 - x)^2 + (x^3 - x)^2 + (x_4 - x)^2 + (x^5 - x)^2]/5 Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation.

Solution

#include<iostream.h>
#include<conio.h>
#include<math.h>
float s_dev(int [],int,float);
float mean_dev(int [],int,float);
void main()
{
float sd,m_dev,avg,sum=0;
int n,b[10],a[20],i,j;
clrscr();
cout<<\"enter the number of elements\";
cin>>n;
cout<<\"enter the elements\";
for(i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
avg=sum/n;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
int temp;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
sd=s_dev(a,n,avg);
m_dev=mean_dev(a,n,avg);
cout<<\"the standard deviation of series: \"<<sd;
cout<<\"\ the mean deviation of series: \"<<m_dev;
getch();
}
float s_dev(int a[],int n,float avg)
{
int i;
float sd,b[20],sum2=0;
for(i=0;i<n;i++)
{
b[i]=pow((a[i]-avg),2);
sum2+=b[i];
}
sd=sqrt(sum2/n);
return(sd);
}
float mean_dev(int a[],int n,float avg)
{
int i;
float b[20],sum2=0,avg2;
for(i=0;i<n;i++)
{
b[i]=abs(a[i]-avg);
sum2+=b[i];
}
avg2=sum2/n;
return(avg2);
}

 Write a program that takes as input five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x_1, x_2, x_3, x_4, a
 Write a program that takes as input five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x_1, x_2, x_3, x_4, a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site