Monday, May 24, 2010

In C++ how do you write a program to input an array and output the standard deviation?

Hi!


Find the folowing program:





#include %26lt;iostream%26gt;


#include %26lt;math.h%26gt;


using namespace std;


int main()


{


int number;


double* array;


int i;


double SD;


double PreSD = 0;


double total = 0;


double mean;


double SDbm;


int a;


cout%26lt;%26lt;"***Standard Deviation***";


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"Enter number of values";


cout%26lt;%26lt;endl;


cin%26gt;%26gt;number;


cout%26lt;%26lt;endl;


array = new double[number];


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"Enter values to calculate Standard Deviation";


cout%26lt;%26lt;endl;


for (int i = 0; i%26lt;number; i = i + 1)


{


cout%26lt;%26lt;i + 1 %26lt;%26lt; ". ";


cin%26gt;%26gt;array[i];


}


for (int i = 0; i%26lt;number; i = i + 1)


{


total = array[i]+total;


}


mean = total/number;


for (int i = 0; i%26lt;number; i = i + 1)


{


PreSD = pow ((array[i]-mean) , 2)+PreSD;


}


SDbm = (PreSD/(number-1));


SD = sqrt (SDbm);


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"Standard Deviation = ";


cout%26lt;%26lt;SD;


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"Mean = ";


cout%26lt;%26lt;mean;


cout%26lt;%26lt;endl;


cout%26lt;%26lt;endl;


system("PAUSE");


cout%26lt;%26lt;endl;


cout%26lt;%26lt;endl;


selection:


cout%26lt;%26lt;"Would you like to find another Standard Deviation?";


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"(1) Yes";


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"(2) No";


cout%26lt;%26lt;endl;


cin%26gt;%26gt;a;


switch(a)


{


case 1:


system("cls");


return main();


break;


case 2:


return 0;


break;


default:


system("cls");


goto selection;


break;


}


}

In C++ how do you write a program to input an array and output the standard deviation?
try above program




















http://www.jobsgala.com

daisy

No comments:

Post a Comment