Define a function that takes a partially filled array of numbers as it arguments
ID: 3634700 • Letter: D
Question
Define a function that takes a partially filled array of numbers as it arguments and returns the standard deviation of the numbers in the partially filled array.Since a partially filled array requires two arguments ,the function will actually have two formal parameters:An array parameter and a formal parameter of type int that gives the number of array positions used,The numbers in the array will be of type double.Embed your function in a suitable test program.the equation is given in the text book?
the solution in the textbook not sufficient.
Explanation / Answer
please rate - thanks
please message me before rating if there is any problem--thanks again
#include <iostream>
#include <math.h>
using namespace std;
double standardd(double[],int);
int main()
{double x[100];
int i=0,j;
double average,sd,sum=0;
do
{cout<<"Enter a number (-9999 when done) ";
cin>>x[i];
i++;
}while(i<100&&x[i-1]!=-9999);
if(x[i-1]==-9999)
i--;
cout<<" Your numbers are: ";
for(j=0;j<i;j++)
{cout<<x[j]<<" ";
if((j+1)%5==0) //5 numbers per line
cout<<endl;
}
cout<<endl;
sd=standardd(x,i);
cout<<"The standard deviation is "<<sd<<" ";
system("pause");
return 0;
}
double standardd(double x[],int n)
{double mean,sum=0,average;
int i;
for(i=0;i<n;i++)
sum+=x[i];
average= (double)sum/n;
for(i=0;i<n;i++)
sum=sum+((x[i]-average)*(x[i]-average));
mean=sum/n;
return sqrt(mean);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.