i try to solve one question to find out the mean, s.d using the file management. even they got no error but when compile it turns out random number so there is logic error but could u point out if i got any mistake. im bad in this chapter though
this is my coding done so far,
Code:
#include<stdio.h>#include<math.h>
main()
{
FILE*real;
int i,j;
float x,s,sd,mean,sum,dev;
sum=0, s=0;
printf("please enter the number of data entered\n");
scanf("%d", &j);
real=fopen("DATA","w");
for (i=1; i<=j; i++)
{
fscanf(real," %f", &x);
fprintf(real," %f", x);
}
fclose(real);
fprintf(real,"\n\n");
real=fopen("DATA","w");
for (i=1; i<=j; i++)
{
sum = sum + x;
printf("sum = %f", sum);
mean= sum/j;
printf("mean = %f", mean);
dev= x - mean;
printf("dev = %f", dev);
s = s + pow(dev,2);
sd = sqrt((s/j));
printf("sd = %f", sd);
}
fclose(real);
}