编写一个程序,打印输入中单词长度的直方图。水平方向直方图。
记录学习过程。
太菜了,写个题花好长时间。
求指点。
#include#define IN 1 #define OUT 0 #define MAXLEN 10 int main() { int c, i, k; int len = 0; int state; int frequency[10]; for (i = 0; i < 10; i++) frequency[i] = 0; while ((c = getchar()) != EOF) { if (c == ' ' || c == ' t' || c == 'n' || c == 'r') { state = OUT; frequency[len]++; len = 0; } else { state = IN; len++; } } for (i = 0; i < 10; i++) { printf("the word lenth: %d - the frequency :%dt", i, frequency[i]); for (k = 1; k <= frequency[i]; k++) { printf("*"); } printf("n"); } getchar(); return 0; }



