Archive:Standard deviation (source code): Difference between revisions

wikademia>JWSchmidt
cat
wikademia>Wikademia
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<pre>#include<stdio.h>
<math>Insert formula here</math>
#include<conio.h>
<source lang="c">#include <math.h>
#include<math.h>
#include <stdio.h>
void main()
#include <stdlib.h>
#define  NUM_MAX  10
/* main: main processing of standard deviation */
/* NOTE: on UNIX you may have to compile with the -lm option
* at the *end* of the command line
*/
int main(void)
{
{
int n,i,d,a[10];
    int n, i, d, a[NUM_MAX];
 
    double x = 0, sd, s = 0, m, sum = 0;
float x,sd=0,s=0,m=0,sum=0;
clrscr();
    printf("enter how many [max %d]: ", NUM_MAX);
printf("enter the number ");
    scanf("%d", &n);
scanf("%d",&n);
for(i=0;i<n;i++)
    if ( n > NUM_MAX )
{
    {
printf("enter the element %d:",i+1);
        printf("You entered a value greater than %d\n", NUM_MAX);
scanf("%d",&a[i]);
        exit(EXIT_FAILURE);
}
    }
for(i=0;i<n;i++)
{
    for (i = 0; i < n; i++)
x=x+a[i];
    {
m=x/n;
        printf("enter integer element %d of %d: ", i + 1, n);
d=a[i]-m;
        scanf("%d", &a[i]);
sum=sum+d*d;
    }
}
s=sum/n;
    for (i = sum = 0; i < n; i++)
sd=sqrt(s);
    {
printf("the number of terms=%d \n",n);
        x = x + a[i];
printf("their mean is m=%f \n",m);
        m = x / n;
printf("standard deviation=%f \n",sd);
        d = a[i] - m;
getch();
        sum += d * d;
    }
    s = sum / n;
    sd = sqrt(s);
    printf("the number of terms = %d\n", n);
    printf("their mean is m     = %f\n", m);
    printf("standard deviation = %f\n", sd);
    /* indicate success */
    exit(EXIT_SUCCESS);
}
}
</pre>
</source>


[[Category:C source code examples]]
[[Category:C source code examples]]