binning integer values in C

169 views Asked by At

I've been at this for about two months by myself and here is my first stand alone program that i wrote by myself. It models the behavior of random variables. It draws SIZEA number of random values between 1 and 100 then enters them into an array and calculates mean and standard deviations. This random experiment can be repeated SIZEB number of times. Mean values of all repeated experiments are again entered into an array and used to calculate expect value of the mean and standard error. Finally, values of each individual experiment and mean values of each experiment are binned (bin size 10 and 5 respectively) and then used to calculate frequencies and histogram. To bin the values I used nested if / else statements producing a relatively large amount of lines of code. I am wondering if anyone can come up with a more elegant solution to binning these values?

Here is the code binning is in lines 27 to 74 and lines 99 to 200.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

//define system constants
#define SIZEA 100
#define SIZEB 300

//i, j, n  are indices

int
main(void)
{
    size_t i = 0;
    int A[SIZEA];
    float B[SIZEB];
    int C[SIZEB];

    srand(time(NULL));
    // outer loop for SIZEB number of individual sampling events
    while (i < SIZEB) {
        printf("\n");
        size_t j = 0;
        int FREQUENCY[10] = { 0 };
        // inner loop for SIZEA number of drawings constituting each sampling
        // event
        while (j < SIZEA) {
            int grade = rand() % 100 + 1;

            A[j] = grade;
            printf("%3d\n", A[j]);

            // bin values of each sampling event
            if (A[j] > 0 && A[j] <= 10) {
                ++FREQUENCY[0];
            }
            else {
                if (A[j] > 10 && A[j] <= 20) {
                    ++FREQUENCY[1];
                }
                else {
                    if (A[j] > 20 && A[j] <= 30) {
                        ++FREQUENCY[2];
                    }
                    else {
                        if (A[j] > 30 && A[j] <= 40) {
                            ++FREQUENCY[3];
                        }
                        else {
                            if (A[j] > 40 && A[j] <= 50) {
                                ++FREQUENCY[4];
                            }
                            else {
                                if (A[j] > 50 && A[j] <= 60) {
                                    ++FREQUENCY[5];
                                }
                                else {
                                    if (A[j] > 60 && A[j] <= 70) {
                                        ++FREQUENCY[6];
                                    }
                                    else {
                                        if (A[j] > 70 && A[j] <= 80) {
                                            ++FREQUENCY[7];
                                        }
                                        else {
                                            if (A[j] > 80 && A[j] <= 90) {
                                                ++FREQUENCY[8];
                                            }
                                            else {
                                                if (A[j] > 90 && A[j] <= 100) {
                                                    ++FREQUENCY[9];
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            ++j;
        // inner loop end
        }
        for (size_t n = 0; n < 10; ++n) {
            printf("\n%3d", FREQUENCY[n]);
        }
        int sum = 0;

        for (j = 0; j < SIZEA; ++j) {
            sum += A[j];
        }
        printf("\n");
        float mean = (float) sum / SIZEA;

        printf("\nMean of Array values is: %1f\n", mean);
        int sumsq = 0;

        for (j = 0; j < SIZEA; ++j) {
            sumsq = sumsq + pow((A[j] - mean), 2);
        }
        printf("Sum of squares is: %1d\n", sumsq);
        int stdev;

        stdev = sqrt(sumsq / SIZEA);
        printf("STDEV is:  %1d\n", stdev);
        B[i] = mean;
        C[i] = stdev;
        ++i;
    // outer loop end
    }
    int FREQUENCYMEAN[20] = { 0 };
    // bin mean values of sampling events
    for (i = 0; i < SIZEB; ++i) {
        if (B[i] > 0 && B[i] <= 5) {
            ++FREQUENCYMEAN[0];
        }
        else {
            if (B[i] > 5 && B[i] <= 10) {
                ++FREQUENCYMEAN[1];
            }
            else {
                if (B[i] > 10 && B[i] <= 15) {
                    ++FREQUENCYMEAN[2];
                }
                else {
                    if (B[i] > 15 && B[i] <= 20) {
                        ++FREQUENCYMEAN[3];
                    }
                    else {
                        if (B[i] > 20 && B[i] <= 25) {
                            ++FREQUENCYMEAN[4];
                        }
                        else {
                            if (B[i] > 25 && B[i] <= 30) {
                                ++FREQUENCYMEAN[5];
                            }
                            else {
                                if (B[i] > 30 && B[i] <= 35) {
                                    ++FREQUENCYMEAN[6];
                                }
                                else {
                                    if (B[i] > 35 && B[i] <= 40) {
                                        ++FREQUENCYMEAN[7];
                                    }
                                    else {
                                        if (B[i] > 40 && B[i] <= 45) {
                                            ++FREQUENCYMEAN[8];
                                        }
                                        else {
                                            if (B[i] > 45 && B[i] <= 50) {
                                                ++FREQUENCYMEAN[9];
                                            }
                                            else {
                                                if (B[i] > 50 && B[i] <= 55) {
                                                    ++FREQUENCYMEAN[10];
                                                }
                                                else {
                                                    if (B[i] > 55 && B[i] <= 60) {
                                                        ++FREQUENCYMEAN[11];
                                                    }
                                                    else {
                                                        if (B[i] > 60 && B[i] <= 65) {
                                                            ++FREQUENCYMEAN[12];
                                                        }
                                                        else {
                                                            if (B[i] > 65 && B[i] <= 70) {
                                                                ++FREQUENCYMEAN[13];
                                                            }
                                                            else {
                                                                if (B[i] > 70 && B[i] <= 75) {
                                                                    ++FREQUENCYMEAN[14];
                                                                }
                                                                else {
                                                                    if (B[i] > 75 && B[i] <= 80) {
                                                                        ++FREQUENCYMEAN[15];
                                                                    }
                                                                    else {
                                                                        if (B[i] > 80 && B[i] <= 85) {
                                                                            ++FREQUENCYMEAN[16];
                                                                        }
                                                                        else {
                                                                            if (B[i] > 85 && B[i] <= 90) {
                                                                                ++FREQUENCYMEAN[17];
                                                                            }
                                                                            else {
                                                                                if (B[i] > 90 && B[i] <= 95) {
                                                                                    ++FREQUENCYMEAN[18];
                                                                                }
                                                                                else {
                                                                                    if (B[i] > 95 && B[i] <= 100) {
                                                                                        ++FREQUENCYMEAN[19];
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    printf("\n");
    int sumE = 0;

    for (i = 0; i < SIZEB; ++i) {
        printf("Mean %1d: %1f\n", i, B[i]);
        sumE = sumE + B[i];
        printf("STDEV %1d: %1d\n", i, C[i]);
    }
    float expectvalue = (float) sumE / SIZEB;

    printf("\nExpect value of mean is: %1f", expectvalue);
    int sumsqE = 0;

    for (i = 0; i < SIZEB; ++i) {
        sumsqE = sumsqE + pow((B[i] - expectvalue), 2);
    }
    int SE;

    SE = sqrt(sumsqE / SIZEB);
    printf("\nSE of Mean is: %1d", SE);
    printf("\n");
    printf("\nFrequency of Expect value of mean:");
    printf("\n%5s%11s%11s", "Bin", "Frequency", "Histogram");
    for (size_t k = 0; k < 20; ++k) {
        printf("\n%4d%9d       ", k, FREQUENCYMEAN[k]);
        for (size_t n = 1; n <= FREQUENCYMEAN[k]; ++n) {
            printf("%c", '.');
        }
        puts("");
    }
}
2

There are 2 answers

0
Ethan Smith On BEST ANSWER

You can find the bin a number resides in by dividing it by the size of the bin

int bin = (A[j] - 1)/ 10;
++FREQUENCY[bin];

int bin = (B[i] - 1) / 5;
++FREQUENCYMEAN[bin];
0
chqrlie On

It is idiomatic in C to not indent the else block if it contains just another if statement.

Here is a modified version of your code with the same tests but no run away extra indentation:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

//define system constants
#define SIZEA 100
#define SIZEB 300

//i, j, n  are indices

int main(void)
{
    size_t i = 0;
    int A[SIZEA];
    float B[SIZEB];
    int C[SIZEB];

    srand(time(NULL));
    // outer loop for SIZEB number of individual sampling events
    while (i < SIZEB) {
        printf("\n");
        size_t j = 0;
        int FREQUENCY[10] = { 0 };
        // inner loop for SIZEA number of drawings constituting each sampling
        // event
        while (j < SIZEA) {
            int grade = rand() % 100 + 1;

            A[j] = grade;
            printf("%3d\n", A[j]);

            // bin values of each sampling event
            if (A[j] > 0 && A[j] <= 10) {
                ++FREQUENCY[0];
            } else
            if (A[j] > 10 && A[j] <= 20) {
                ++FREQUENCY[1];
            } else
            if (A[j] > 20 && A[j] <= 30) {
                ++FREQUENCY[2];
            } else
            if (A[j] > 30 && A[j] <= 40) {
                ++FREQUENCY[3];
            } else
            if (A[j] > 40 && A[j] <= 50) {
                ++FREQUENCY[4];
            } else
            if (A[j] > 50 && A[j] <= 60) {
                ++FREQUENCY[5];
            } else
            if (A[j] > 60 && A[j] <= 70) {
                ++FREQUENCY[6];
            } else
            if (A[j] > 70 && A[j] <= 80) {
                ++FREQUENCY[7];
            } else
            if (A[j] > 80 && A[j] <= 90) {
                ++FREQUENCY[8];
            } else
            if (A[j] > 90 && A[j] <= 100) {
                ++FREQUENCY[9];
            }
            ++j;
            // inner loop end
        }
        for (size_t n = 0; n < 10; ++n) {
            printf("\n%3d", FREQUENCY[n]);
        }
        int sum = 0;

        for (j = 0; j < SIZEA; ++j) {
            sum += A[j];
        }
        printf("\n");
        float mean = (float) sum / SIZEA;

        printf("\nMean of Array values is: %1f\n", mean);
        int sumsq = 0;

        for (j = 0; j < SIZEA; ++j) {
            sumsq = sumsq + pow((A[j] - mean), 2);
        }
        printf("Sum of squares is: %1d\n", sumsq);
        int stdev;

        stdev = sqrt(sumsq / SIZEA);
        printf("STDEV is:  %1d\n", stdev);
        B[i] = mean;
        C[i] = stdev;
        ++i;
        // outer loop end
    }
    int FREQUENCYMEAN[20] = { 0 };
    // bin mean values of sampling events
    for (i = 0; i < SIZEB; ++i) {
        if (B[i] > 0 && B[i] <= 5) {
            ++FREQUENCYMEAN[0];
        } else
        if (B[i] > 5 && B[i] <= 10) {
            ++FREQUENCYMEAN[1];
        } else
        if (B[i] > 10 && B[i] <= 15) {
            ++FREQUENCYMEAN[2];
        } else
        if (B[i] > 15 && B[i] <= 20) {
            ++FREQUENCYMEAN[3];
        } else
        if (B[i] > 20 && B[i] <= 25) {
            ++FREQUENCYMEAN[4];
        } else
        if (B[i] > 25 && B[i] <= 30) {
            ++FREQUENCYMEAN[5];
        } else
        if (B[i] > 30 && B[i] <= 35) {
            ++FREQUENCYMEAN[6];
        } else
        if (B[i] > 35 && B[i] <= 40) {
            ++FREQUENCYMEAN[7];
        } else
        if (B[i] > 40 && B[i] <= 45) {
            ++FREQUENCYMEAN[8];
        } else
        if (B[i] > 45 && B[i] <= 50) {
            ++FREQUENCYMEAN[9];
        } else
        if (B[i] > 50 && B[i] <= 55) {
            ++FREQUENCYMEAN[10];
        } else
        if (B[i] > 55 && B[i] <= 60) {
            ++FREQUENCYMEAN[11];
        } else
        if (B[i] > 60 && B[i] <= 65) {
            ++FREQUENCYMEAN[12];
        } else
        if (B[i] > 65 && B[i] <= 70) {
            ++FREQUENCYMEAN[13];
        } else
        if (B[i] > 70 && B[i] <= 75) {
            ++FREQUENCYMEAN[14];
        } else
        if (B[i] > 75 && B[i] <= 80) {
            ++FREQUENCYMEAN[15];
        } else
        if (B[i] > 80 && B[i] <= 85) {
            ++FREQUENCYMEAN[16];
        } else
        if (B[i] > 85 && B[i] <= 90) {
            ++FREQUENCYMEAN[17];
        } else
        if (B[i] > 90 && B[i] <= 95) {
            ++FREQUENCYMEAN[18];
        } else
        if (B[i] > 95 && B[i] <= 100) {
            ++FREQUENCYMEAN[19];
        }
    }
    printf("\n");
    int sumE = 0;

    for (i = 0; i < SIZEB; ++i) {
        printf("Mean %1d: %1f\n", i, B[i]);
        sumE = sumE + B[i];
        printf("STDEV %1d: %1d\n", i, C[i]);
    }
    float expectvalue = (float) sumE / SIZEB;

    printf("\nExpect value of mean is: %1f", expectvalue);
    int sumsqE = 0;

    for (i = 0; i < SIZEB; ++i) {
        sumsqE = sumsqE + pow((B[i] - expectvalue), 2);
    }
    int SE;

    SE = sqrt(sumsqE / SIZEB);
    printf("\nSE of Mean is: %1d", SE);
    printf("\n");
    printf("\nFrequency of Expect value of mean:");
    printf("\n%5s%11s%11s", "Bin", "Frequency", "Histogram");
    for (size_t k = 0; k < 20; ++k) {
        printf("\n%4d%9d       ", k, FREQUENCYMEAN[k]);
        for (size_t n = 1; n <= FREQUENCYMEAN[k]; ++n) {
            printf("%c", '.');
        }
        puts("");
    }
    return 0;
}

Since the bins have the same width, it is easy to compute the bin number from the value:

    int bin = (grade - 1) / 10;
    ++FREQUENCY[bin];

The same applies for the mean array B:

    int bin = (B[i] - 1) / 5;
    ++FREQUENCYMEAN[bin];

You must ensure that bin is always in the proper range, but it seems to be the case by construction as all random values are in the range 1..100 hence the means are in the same range exactly, producing values of bin in 0..9 fot FREQUENCY and 0..19 for FREQUENCYMEAN.

Here is a simplified version:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

//define system constants
#define SIZEA 100
#define SIZEB 300

//i, j, n  are indices

int main(void)
{
    size_t i = 0;
    int A[SIZEA];
    float B[SIZEB];
    int C[SIZEB];

    srand(time(NULL));
    // outer loop for SIZEB number of individual sampling events
    while (i < SIZEB) {
        printf("\n");
        size_t j = 0;
        int FREQUENCY[10] = { 0 };
        // inner loop for SIZEA number of drawings constituting each sampling
        // event
        while (j < SIZEA) {
            int grade = rand() % 100 + 1;

            A[j] = grade;
            printf("%3d\n", A[j]);

            // bin values of each sampling event
            int bin = (grade - 1) / 10;
            ++FREQUENCY[bin];
            ++j;
            // inner loop end
        }
        for (size_t n = 0; n < 10; ++n) {
            printf("\n%3d", FREQUENCY[n]);
        }
        int sum = 0;

        for (j = 0; j < SIZEA; ++j) {
            sum += A[j];
        }
        printf("\n");
        float mean = (float) sum / SIZEA;

        printf("\nMean of Array values is: %1f\n", mean);
        int sumsq = 0;

        for (j = 0; j < SIZEA; ++j) {
            sumsq = sumsq + pow((A[j] - mean), 2);
        }
        printf("Sum of squares is: %1d\n", sumsq);
        int stdev;

        stdev = sqrt(sumsq / SIZEA);
        printf("STDEV is:  %1d\n", stdev);
        B[i] = mean;
        C[i] = stdev;
        ++i;
        // outer loop end
    }
    int FREQUENCYMEAN[20] = { 0 };
    // bin mean values of sampling events
    for (i = 0; i < SIZEB; ++i) {
        int bin = (B[i] - 1) / 5;
        ++FREQUENCYMEAN[bin];
    }
    printf("\n");
    int sumE = 0;

    for (i = 0; i < SIZEB; ++i) {
        printf("Mean %1d: %1f\n", i, B[i]);
        sumE = sumE + B[i];
        printf("STDEV %1d: %1d\n", i, C[i]);
    }
    float expectvalue = (float) sumE / SIZEB;

    printf("\nExpect value of mean is: %1f", expectvalue);
    int sumsqE = 0;

    for (i = 0; i < SIZEB; ++i) {
        sumsqE = sumsqE + pow((B[i] - expectvalue), 2);
    }
    int SE;

    SE = sqrt(sumsqE / SIZEB);
    printf("\nSE of Mean is: %1d", SE);
    printf("\n");
    printf("\nFrequency of Expect value of mean:");
    printf("\n%5s%11s%11s", "Bin", "Frequency", "Histogram");
    for (size_t k = 0; k < 20; ++k) {
        printf("\n%4d%9d       ", k, FREQUENCYMEAN[k]);
        for (size_t n = 1; n <= FREQUENCYMEAN[k]; ++n) {
            printf("%c", '.');
        }
        puts("");
    }
    return 0;
}

Compiling this code with advanced warnings clang -Weverything produces many useful warnings:

240101-binning.c:50:52: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]
        printf("\nMean of Array values is: %1f\n", mean);
        ~~~~~~                                     ^~~~
240101-binning.c:54:27: warning: implicit conversion turns floating-point number into integer: 'double' to 'int' [-Wfloat-conversion]
            sumsq = sumsq + pow((A[j] - mean), 2);
                  ~ ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
240101-binning.c:54:39: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]
            sumsq = sumsq + pow((A[j] - mean), 2);
                            ~~~  ~~~~~^~~~~~
240101-binning.c:54:34: warning: implicit conversion from 'int' to 'float' may lose precision [-Wimplicit-int-float-conversion]
            sumsq = sumsq + pow((A[j] - mean), 2);
                                 ^~~~ ~
240101-binning.c:59:17: warning: implicit conversion turns floating-point number into integer: 'double' to 'int' [-Wfloat-conversion]
        stdev = sqrt(sumsq / SIZEA);
              ~ ^~~~~~~~~~~~~~~~~~~
240101-binning.c:69:30: warning: implicit conversion turns floating-point number into integer: 'float' to 'int' [-Wfloat-conversion]
        int bin = (B[i] - 1) / 5;
            ~~~   ~~~~~~~~~~~^~~
240101-binning.c:76:35: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
        printf("Mean %1d: %1f\n", i, B[i]);
                     ~~~          ^
                     %1zu
240101-binning.c:76:38: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]
        printf("Mean %1d: %1f\n", i, B[i]);
        ~~~~~~                       ^~~~
240101-binning.c:77:21: warning: implicit conversion turns floating-point number into integer: 'float' to 'int' [-Wfloat-conversion]
        sumE = sumE + B[i];
             ~ ~~~~~^~~~~~
240101-binning.c:77:16: warning: implicit conversion from 'int' to 'float' may lose precision [-Wimplicit-int-float-conversion]
        sumE = sumE + B[i];
               ^~~~ ~
240101-binning.c:78:36: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
        printf("STDEV %1d: %1d\n", i, C[i]);
                      ~~~          ^
                      %1zu
240101-binning.c:82:46: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]
    printf("\nExpect value of mean is: %1f", expectvalue);
    ~~~~~~                                   ^~~~~~~~~~~
240101-binning.c:86:25: warning: implicit conversion turns floating-point number into integer: 'double' to 'int' [-Wfloat-conversion]
        sumsqE = sumsqE + pow((B[i] - expectvalue), 2);
               ~ ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
240101-binning.c:86:37: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]
        sumsqE = sumsqE + pow((B[i] - expectvalue), 2);
                          ~~~  ~~~~~^~~~~~~~~~~~~
240101-binning.c:90:10: warning: implicit conversion turns floating-point number into integer: 'double' to 'int' [-Wfloat-conversion]
    SE = sqrt(sumsqE / SIZEB);
       ~ ^~~~~~~~~~~~~~~~~~~~
240101-binning.c:96:35: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
        printf("\n%4d%9d       ", k, FREQUENCYMEAN[k]);
                  ~~~             ^
                  %4zu
240101-binning.c:97:30: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
        for (size_t n = 1; n <= FREQUENCYMEAN[k]; ++n) {
                           ~ ^  ~~~~~~~~~~~~~~~~
17 warnings generated.

Here are the explanations:

  • the conversion for type size_t is %zu, not %d that expects an int value, which may have a different representation, especially on 64-bit systems.
  • you should use type double instead of float for more accurate statistics. float values are automatically converted to double when passed to printf anyway.
  • stdev, sumsq, ... should have a floating point type.
  • the printf conversion %1f is pointless. You might have misread %lf, but the l in the latter is ignored by printf anyway.

Here is a modified version with all these warnings fixed:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

//define system constants
#define SIZEA 100
#define SIZEB 300

int main(void)
{
    int A[SIZEA];
    double B[SIZEB];
    double C[SIZEB];

    srand(time(NULL));
    // outer loop for SIZEB number of individual sampling events
    for (size_t i = 0; i < SIZEB; i++) {
        int FREQUENCY[10] = { 0 };
        // inner loop for SIZEA number of drawings constituting each sampling
        // event
        for (size_t j = 0; j < SIZEA; j++) {
            int grade = rand() % 100 + 1;

            A[j] = grade;
            printf("%3d\n", A[j]);

            // bin values of each sampling event
            int bin = (grade - 1) / 10;
            ++FREQUENCY[bin];
        }
        printf("\n");
        for (size_t n = 0; n < 10; ++n) {
            printf("%3d\n", FREQUENCY[n]);
        }
        printf("\n");

        double sum = 0;
        for (size_t j = 0; j < SIZEA; ++j) {
            sum += A[j];
        }
        double mean = sum / SIZEA;
        printf("Mean of Array values is: %f\n", mean);

        double sumsq = 0;
        for (size_t j = 0; j < SIZEA; ++j) {
            sumsq += pow(A[j] - mean, 2);
        }
        printf("Sum of squares is: %f\n", sumsq);

        double stdev = sqrt(sumsq / SIZEA);
        printf("STDEV is:  %f\n", stdev);
        B[i] = mean;
        C[i] = stdev;
        printf("\n");
    }  // outer loop end

    int FREQUENCYMEAN[20] = { 0 };
    // bin mean values of sampling events
    for (size_t i = 0; i < SIZEB; ++i) {
        int bin = (int)((B[i] - 1) / 5);
        ++FREQUENCYMEAN[bin];
    }

    double sumE = 0;
    for (size_t i = 0; i < SIZEB; ++i) {
        printf("Mean %zu: %f\n", i, B[i]);
        sumE += B[i];
        printf("STDEV %zu: %f\n", i, C[i]);
    }
    double expectvalue = sumE / SIZEB;
    printf("Expect value of mean is: %f\n", expectvalue);

    double sumsqE = 0;
    for (size_t i = 0; i < SIZEB; ++i) {
        sumsqE += pow(B[i] - expectvalue, 2);
    }
    double SE = sqrt(sumsqE / SIZEB);
    printf("SE of Mean is: %f\n", SE);
    printf("\n");

    printf("Frequency of Expect value of mean:\n");
    printf("%5s%11s%11s\n", "Bin", "Frequency", "Histogram");
    for (size_t k = 0; k < 20; ++k) {
        printf("%4zu%9d       ", k, FREQUENCYMEAN[k]);
        for (int n = 1; n <= FREQUENCYMEAN[k]; ++n) {
            putchar('.');
        }
        printf("\n");
    }
    printf("\n");
    return 0;
}