-
Notifications
You must be signed in to change notification settings - Fork 0
/
6histo.c
61 lines (50 loc) · 1.04 KB
/
6histo.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
#include <stdio.h>
#define MAX 100
int getword( int max);
int main()
{
int count = 0;
int range, j;
int longest = 0;
int frequency = 0;
int v; // vertical axis
int h; // horizontal axis
int length[MAX];
for ( j = 0; j <= MAX; j++)
length[j] = 0;
while (( count = getword(MAX)) > 0 )
{
printf(" length: %d \n", count );
if ( count > longest )
longest = count;
length[count] += 1;
}
for ( range = 0; range <= longest; range++)
{
printf("length[%d] equals: \t %d \n", range, (length[range]));
if ( (length[range]) > frequency)
frequency = (length[range]);
}
printf("highest frequency equals: \t %d \n", frequency);
for ( v = frequency; v >= 0; v--)
{
for ( h = 1; h <= longest; h++);
{
if ( (length[h]) >= v)
putchar('#');
else
putchar(' ');
}
putchar('\n');
}
return 0;
}
/* getword: count letters in word and return length */
int getword(limit)
{
int i, c;
i = c = 0;
while (( --limit > 0) && (( c = getchar()) != EOF) && ( c != ' ' && c != '\t' && c != '\n' ))
++i;
return i;
}