-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.c
57 lines (50 loc) · 1.64 KB
/
stat.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
#include <stdio.h>
#include <stdlib.h>
void main()
{
char buf[64];
double cnt = 0, sum = 0, sd = 0, max = 0, min = 0, avg, i, j = 0, k = 0, l = 0, m = 0, n = 0;
FILE *f;
if ((f = fopen("stat.txt", "r")) == NULL) return;
while (fgets(buf, 64, f) != NULL) {
i = atof(buf);
if (i > max || cnt == 0) max = i;
if (i < min || cnt == 0) min = i;
cnt++;
sum += i;
sd += i * i;
}
fclose(f);
if (cnt == 0) return;
avg = sum / cnt;
sd = sqrt(sd / cnt - avg * avg);
printf("” F%.0f\n", cnt);
printf("•½‹Ï F%f\n", avg);
printf("•W€•Î·F%f\n", sd);
printf("•½}1ƒÐ F%f ` %f\n", avg - sd, avg + sd);
printf("•½}2ƒÐ F%f ` %f\n", avg - sd * 2, avg + sd * 2);
printf("•½}3ƒÐ F%f ` %f\n", avg - sd * 3, avg + sd * 3);
printf("Å‘å F%f\n", max);
printf("Ŭ F%f\n", min);
max = avg + sd;
min = avg - sd;
max = floor(max < 0 ? max - 0.5 : max + 0.5);
min = floor(min < 0 ? min - 0.5 : min + 0.5);
avg = floor(avg < 0 ? avg - 0.5 : avg + 0.5);
if ((f = fopen("stat.txt", "r")) == NULL) return;
while (fgets(buf, 64, f) != NULL) {
i = atof(buf);
if (i < avg) j++;
else if (i > avg) k++;
else l++;
if (i < min) m++;
else if (i > max) n++;
}
fclose(f);
printf("•½‹Ï= F%.0f / %.0f = %f%%\n", l, cnt, l / cnt * 100);
printf("•½‹Ï> F%.0f / %.0f = %f%%\n", j, cnt, j / cnt * 100);
printf("•½‹Ï< F%.0f / %.0f = %f%%\n", k, cnt, k / cnt * 100);
printf("•½‹Ï1ƒÐ>F%.0f / %.0f = %f%%, / %.0f = %f%%\n", m, cnt, m / cnt * 100, j, m / j * 100);
printf("•½‹Ï1ƒÐ<F%.0f / %.0f = %f%%, / %.0f = %f%%\n", n, cnt, n / cnt * 100, k, n / k * 100);
getch();
}