hist.c |
#include <stdio.h> main(){ enum boolean { OUT, IN }; int c, nw, state, i; float max, temp; int x, y; float wlength[30]; state = OUT; nw = max = temp = 0; for(i = 0; i<nw; ++i) wlength[i]=0; while((c=getchar())!=EOF){ if(c==' '||c=='\n'||c=='\t'){ state = OUT; if(temp>max){ max = temp; temp = 0; } } else if(state==OUT){ state = IN; ++nw; } if(c!=' '||c!='\n'||c!='\t'){ ++wlength[nw]; ++temp; } } for(x = max; x >= 1; --x){ printf("%d", x); if(x<10) printf(" "); for(y = 0; y < nw; ++y){ if(wlength[y]>=x) printf("*"); else printf(" "); printf(" "); } printf("\n"); } for(y = 0; y < nw; ++y){ if(y==0) printf(" "); printf(" "); printf("%d", y); } for(y = 0; y < nw; ++y){ printf("\n"); printf("%.0f", wlength[y]); } printf("\n"); return 0; } |
James Little |