Dec 1, 2019 at 5:52am UTC
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
void fillArray(int a[], int size);
void printArray(int a[], int size);
int main()
{
const int size = 10;
int array[size];
fillArray(array, size);
void printArray(int a[], int size){
for(int i = 0; i<size; i++)
cout << array[i] << " ";
}
int sum = 0;
int sumSq = 0;
double mean, stdDev;
for (int i = 0; i < size; ++i) {
sum += array[i];
sumSq += array[i]*array[i];
}
mean = (double)sum/size;
cout << fixed << "Mean is " << setprecision(2) << mean << endl;
stdDev = sqrt((double)sumSq/size - mean*mean);
cout << fixed << "Std dev is " << setprecision(2) << stdDev << endl;
rturn 0;
}
Last edited on Dec 1, 2019 at 5:55am UTC
Dec 1, 2019 at 1:22pm UTC
Thank you, It works well with my rand() :
void fillArray(int array[], int size)
{
for(int i = 0; i<size; i++)
{
srand(time(0));
for(int i = 0; i<size; i++)
array[i] = (rand() % 99) + 1;
}