#TC1017 #WSQ10
This programm was very easy, since the formulas are well known by now, we have used them a lot in other classes. And arrays are my favorite part of C++ so far. I think they are very intuitive to use, and make soving problems like these, with a big set of numbers, quite easy to solve.
Source Code below: [GitHub Link: https://github.com/diegodamy/WSQ10 ]
#include <iostream>
#include <math.h>
using namespace std;
float STDV (int size2, float st){
double stdv;
return stdv = sqrt(st/(size2-1));
}
float ST(int list2[], int size2, float average){
double st;
for(int i = 0; i <size2; i++){
st += pow((list2[i] – average),2);
}
return st;
}
float GetAverage (int list[], int size){
float sum = 0.0;
float result = 0.0;
for ( int n = 0; n <size; n++){
sum += list[n];
}
return result = sum / size;
}
int main(){
int array [10];
double average;
double st;
cout << “Please enter ten numbers:” << endl;
for (int i = 0; i<10; i++){
cin >> array [i];
}
average = GetAverage (array, 10);
cout << “Average is ” << average;
st = ST(array,10,average);
cout << endl << “Standard deviation is: ” << STDV (10,st);
}
——————————–
Photo Credit: <a href=”https://www.flickr.com/photos/50318388@N00/23640476465/”>mag3737</a> via <a href=”http://compfight.com”>Compfight</a> <a href=”https://creativecommons.org/licenses/by-nc-sa/2.0/”>cc</a>
Arrays, simple yet useful by diegodamy is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.