C++ Adding Chi-Square equation

closed account (EUfE8vqX)
Sample Output
How many numbers? 7
Input a number -- 12
Input a number -- 22
Input a number -- 34
Input a number -- 43
Input a number -- 45
Input a number -- 54
Input a number -- 99
You have entered the following numbers
12
22
34
43
45
54
99
What is the standard deviation of the population? 30
The Sum of the sample is: 309
The Average of the sample is: 44.1429
The Biased Variance of the sample is: 676.408
The Standard Deviation of the sample is: 26.0078
The Chi-Square Distribution is: 4.5093

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 #include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n, count;
    float sum, avg, variance, stand;

    sum = 0;
    variance = 0;
    avg = 0;
    stand = 0;

    cout << "How many numbers?  ";
    cin >> n;

    float x[n];

    for (count=0; count<=(n-1); count++)
    {
        cout << "Input a Number -- ";
        cin >> x[count];
        sum = sum + x[count];
    }

    avg = sum / n;

    for (count=0; count<n; count++)
    {
        variance = variance + pow((x[count] - avg),2) / n;
    }

    stand = sqrt(variance);

    cout << "The sum is: " << sum << endl;
    cout << "The average is  " << avg << endl;
    cout << "The biased variance is " << variance << endl;
    cout << "The standard deviation is " << stand << endl;
    
    char c; cin >> c;

    return 0;
}
Topic archived. No new replies allowed.