Skip to content

Instantly share code, notes, and snippets.

@rodrigoflores
Created December 3, 2010 12:55
Show Gist options
  • Save rodrigoflores/726920 to your computer and use it in GitHub Desktop.
Save rodrigoflores/726920 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include <time.h>
#define VMAX 1000
#define NMAX 67.0
int main()
{
int j;
double average,stddev, S[VMAX], Freq[VMAX], Dist[VMAX];
FILE *statdata, *data;
data=fopen("data.txt","r");
statdata=fopen("stat-data.txt","w");
while(fscanf(data,"%lf", &S[j]) > 0) {
fscanf(data,"%lf", &Freq[j]);
Dist[j]=fabs(S[j]*Freq[j]-NMAX);
}
for(j=0, average=0.0;NMAX>j;j=j+1)
average=Dist[j]+average;
average=average/NMAX;
for(j=0, stddev=0.0;NMAX>j;j=j+1)
stddev=(average-Dist[j])*(average-Dist[j])+stddev;
stddev=stddev/NMAX;
stddev=sqrt(stddev);
if(average-(stddev*3)<0)
fprintf(statdata,"the sample is very bad, the average distance is %g and the standard deviation is %g",average, stddev);
else if(average-(stddev*3)>1)
fprintf(statdata,"the sample is very good, the average distance is %g and the standard deviation is %g",average, stddev);
else
fprintf(statdata,"the sample is ok, the average distance is %g and the standard deviation is %g. We recommend to add more data",average, stddev);
fclose(data);
fclose(statdata);
//system("PAUSE");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment