include SAMPLER include stdio include math include stdlib double 100 i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<SAMPLER.H>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double x[100];
int i,n;
double mean;
double std;
void meanstd( double *x, int length, double mean, double std_dev)
{
int i;
double sum_x, sum_sq, xt;
sum_x=0.0;
sum_sq=0.0;
for( i=0; i<length; i++)
{ xt=x[i]; sum_x=sum_x+xt; sum_sq=sum_sq+xt*xt; }
mean=sum_x/length;
std_dev=sqrt((sum_sq-pow(sum_x, 2)/length)/(length-1));
}
int main (void)
{
SAMPLE;
mean=0;
std=0;
n=100;
for(i=0; i<n; i++)
x[i]=rand()%100;
meanstd(x,n, mean, std);
SAMPLE;
return 0;
}