0

I need help in calculating the variance for randomly generated values (using srand(seed)). When i input 5 i should get 97359589.15265 but i am getting 1.29888e+010. I am almost positive i went wrong in the calculation of the variance but have no idea what to do in making it correct. Any help or suggestions would greatly be appreciated. (My code thus far):

```
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main (){
double getMean(int a[], int n);
double getVariance(int a[], int n);
const int N = 50;
unsigned int seed;
int arr[N];
cout << " Enter a positive integer seed value: \n";
cin >> seed;
srand(seed);
for (int k=0; k<N; k++)
{
arr[k] = rand();
}
cout << endl << " The Mean of the 50 random numbers is: " << getMean(arr, N)<< endl;
cout << endl << " The Variance of the 50 random numbers is: " << getVariance(arr, N)<< endl;
system ("PAUSE");
return 0;
}
double getMean(int a[], int n)
{
double sum(0);
for (int i=0; i<n; i++)
sum +=a[i];
return sum/n;
}
double getVariance(int a[], int n)
{
double sum1(0);
for (int i=0; i<n; i++)
sum1 +=a[i];
return ((pow((sum1-(sum1/n)),2))/n);
}
```