Search code examples
c++arraysstatisticsprobabilitynormal-distribution

How to change the z value to the one from the table (Z-Table from Normal Distribution) in C++?


i have task to make a program using C++ to calculate a probability using a normal distribution. If i already found the Z value, how to change it to become the one from the Z table? Like -0.55, in the z-table is 0.29116. And 0.85 in the table is 0.80234.

Because what i know array is only know what column and row to display. Thanks.

Z Table


Solution

  • The table is for the Cumulative Normal Distribution Function. This is easiest to implement using the erfc standard library math function:

    double cumulativeNormal(double x) {
        return 0.5 * std::erfc(-x * M_SQRT1_2);
    }
    
    int main() {
        std::cout << cumulativeNormal(-0.55) << '\n';  // prints 0.29116
    }