-
Notifications
You must be signed in to change notification settings - Fork 1
/
standarddeviation.c
86 lines (69 loc) · 2.5 KB
/
standarddeviation.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
void main(){int n;
float xi[15];
float cf[15];
float f[15]; int i,j;
float lower[15];
float upper[15];
printf("enter the number of values to enter:\n");
scanf("%d",&n);
printf("enter the lower bound and upper bound and its frequency:\n");
for(i=0;i<n;i++)
{
scanf("%f %f %f",&lower[i],&upper[i],&f[i]);
}
cf[0]=f[0];
for(i=1;i<n;i++)
{
cf[i]=cf[i-1]+ f[i];
}
for(i=0;i<n;i++)
{
xi[i]=(lower[i]+upper[i])/2;
}
float interval=upper[0]-lower[0];
printf("the table formed:");
printf("RANGE FREQUENCY CF XI\n");
for(i=0;i<n;i++)
{
printf("%f - %f %f %f %f\n",lower[i],upper[i],f[i],cf[i],xi[i]);
}
float sum=0,ntotal=0;
for(i=0;i<n;i++)
{
ntotal=cf[n-1];
sum+=(xi[i] * f[i]);
} float mean;
printf("%f\n", sum);
printf("%f\n", ntotal);
mean=sum/ntotal;
printf("the mean = %f\n",mean);
float freq= ntotal/2; int medclasspos;
for(i=0;i<n;i++)
{
if(cf[i]>freq&& cf[i-1]<freq)
{ medclasspos=i;
break;}} float median;
median=lower[medclasspos]+(freq-cf[medclasspos-1])*interval/f[medclasspos];
printf("median=%f\n",median);
int maxf=f[0];
int modeclasspos=0;
for(i=0;i<n;i++){
if(maxf<f[i]){
maxf=f[i];
modeclasspos=i;
}
}
float mode;
mode=lower[modeclasspos]+(f[modeclasspos]-f[modeclasspos-1])/(2*f[modeclasspos]-f[modeclasspos-1]-f[modeclasspos+1])*interval;
printf("mode=%f",mode);
float t;
float sd;
for(i=0;i<n;i++)
{
t+=(pow(mean-xi[i],2))*f[i];
}
t/=ntotal;
printf("%f\n",t);
sd=pow(t,0.5);
printf("\nstandard deviation of the data is =%f",sd);
}