-6

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.

xLokos
  • 69
  • 1
  • 9
  • 3
    You got to hand it to them these lecturers are getting more imaginative with the homework. Write some code! – Ed Heal Jan 25 '14 at 16:29
  • 3
    homework question again - at least the lecturer is more imaginative – Ed Heal Jan 25 '14 at 16:31
  • Do you think some lecturers will post some code to catch these people out? – Ed Heal Jan 25 '14 at 16:32
  • Is there any reason not to store into an array? – Patricia Shanahan Jan 25 '14 at 16:33
  • @xLokos - Some code - indent it, At least you have started to write an answer for the homework. Test it – Ed Heal Jan 25 '14 at 16:56
  • ... See if it compiles – Ed Heal Jan 25 '14 at 16:57
  • It is generally a mistake to get into a situation in which you have to ask "Is this correct?". Begin by writing a very short simple but complete program that does a subset of the job - fixed size file, matching fixed array size, only calculate one statistic. Compile and test that. Then add features, one at a time, always compiling and testing, until you have the program you need. – Patricia Shanahan Jan 25 '14 at 17:03
  • Salami tactics - see http://www.youtube.com/watch?v=IX_d_vMKswE – Ed Heal Jan 25 '14 at 17:20

1 Answers1

2
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.

Thomas
  • 174,939
  • 50
  • 355
  • 478
  • `257<<23` is a signed overflow (undefined behavior) on a typical 32-bit compilation platform. I would recommend `i=-0x1.fffffep127`. – Pascal Cuoq Jan 25 '14 at 23:03