Created
December 3, 2010 12:55
-
-
Save rodrigoflores/726921 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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