IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
COne Dimensional Arrays : Computing Statistics with Arrays
<07.03>
/* This program computes the meand and standard deviations of the values inside an array */ #include <stdio.h> #include <math.h> #define MAX 5 int main (void) { double mean, sd, sum, sumsq; double x[] = {10.0, 15.0, 20.0, 10.0, 30.0}; int i; sum = 0; sumsq = 0; /* computing the sum and sum of squares */ for (i=0; i<MAX; ++i) { sum = sum + x[i]; sumsq = sumsq + x[i] * x[i]; } /* computing mean and standard deviation */ mean = sum / MAX; sd = sqrt(sumsq / MAX - mean * mean); /* printing report */ printf ("The mean is %lf. \n", mean); printf ("The standard deviation is %lf. \n", sd); return (0); }
Hergestellt in Deutschland / Made in Germany
The mean is 17.000000. The standard deviation is 7.483315.
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland