Pregunta

I need some help with writing such program which would read a .txt file containing large (but unknown) number of floating point numbers separated by whitespaces (name of the file has to be given by user) and calculate the size of the sample, max and min, mean, median and standart deviation.

Do i have to read the file and put it into array? Or is there another way?

Also I have to write this in C language.

¿Fue útil?

Solución

float x,i=~(257<<23),a,s,t;main(int n,char**f){a=-i;f=fopen(f[1],"r"
);for(n=0;fscanf(f,"%f",&x)>0;n++,s+=x,x<i?i=x:0,x>a?a=x:0,t+=x*x);
printf("%d %f %f %f %f\n",n,a,i,s/n,sqrtf(t/n));} 

Sorry for the long code. Didn't have time to make it shorter.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top