-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise1-14.c
48 lines (39 loc) · 1.12 KB
/
exercise1-14.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
#include <stdio.h>
#define MAXCHAR 128
int main(void)
{
int c, i, j, maxfrequency;
int frequency[MAXCHAR];
maxfrequency = 0;
for (i = 0; i < MAXCHAR; ++i) {
frequency[i] = 0;
}
while ((c = getchar()) != EOF)
if (c < MAXCHAR)
++frequency[c];
for (i = 0; i < MAXCHAR; ++i)
if (i != ' ' && i != '\n' && i != '\t' && frequency[i] > maxfrequency)
maxfrequency = frequency[i];
printf("draw the histogram with the bars vertical: \n");
for (i = 0; i < maxfrequency; ++i) {
printf("%3d |", maxfrequency -i);
for (j = 0; j < MAXCHAR; ++j) {
if (j != ' ' && j != '\n' && j != '\t' && frequency[j] > 0) {
if (i < (maxfrequency - frequency[j]))
printf(" ");
else
printf("+ ");
}
}
printf("\n");
}
printf(" ");
for (i = 0; i < MAXCHAR; ++i) {
if (i != ' ' && i != '\n' && i != '\t' && frequency[i] > 0) {
putchar(i);
printf(" ");
}
}
printf("\n");
return 0;
}