1 /* Write a program to print a histogram of the lengths of words in
2 * its input. It is easy to draw the histogram with the bars horizontal;
3 * a vertical orientation is more challenging. */
10 int histogram[MAXLENGTH+1], letters, c, maxfreq;
12 for (int i = 1; i <= MAXLENGTH; ++i)
17 while ((c = getchar()) != EOF) {
18 if (c == ' ' || c == '\t' || c == '\n') {
27 for (int i = 1; i <= MAXLENGTH; ++i) {
28 printf("%2d: %5d", i, histogram[i]);
29 for (int j = 0; j < histogram[i]; ++j) {
34 maxfreq = (histogram[i] > maxfreq ? histogram[i] : maxfreq);
37 for (int h = maxfreq; h > 0; --h) {
38 for (int i = 1; i <= MAXLENGTH; ++i) {
39 if (histogram[i] >= h) {
47 for (int i = 1; i <= MAXLENGTH; ++i) {
51 for (int i = 1; i <= MAXLENGTH; ++i) {