Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
670 B
2
Indexable
Never
#include <stdio.h>
#include <math.h>

typedef int IntArray[25];

int main() {
    IntArray values = {12, 34, 56, 78, 90, 23, 45, 67, 89, 21, 43, 65, 87, 9, 32, 54, 76, 98, 10, 31, 53, 75, 97, 19, 87};

    double mean, sd;
    calculateMeanAndSD(values, &mean, &sd);

    printf("Mean: %lf\n", mean);
    printf("Standard Deviation: %lf\n", sd);

    return 0;
}

void calculateMeanAndSD(const IntArray values, double *mean, double *sd) {

    *mean = 0.0;
    for (int i = 0; i < 25; i++) {
        *mean += values[i];
    }
    *mean /= 25;

    *sd = 0.0;
    for (int i = 0; i < 25; i++) {
        *sd += pow(values[i] - *mean, 2);
    }
    *sd = sqrt(*sd / 25);
}