Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Write a program to print a histogram of the lengths of words in its input.
- It is easy to draw the histogram with the bars horizontal; a vertical orientation is more challenging.*/
- #include <stdio.h>
- main()
- {
- int c,i,NumberOfCharacters=0,Counter;
- int nchar[10];
- for(i=0;i<10;++i)
- {
- nchar[i]=0;
- }
- while ((c=getchar())!=EOF)
- {
- while(c!=' '&&c!='\n'&&c!='\t')
- { ++NumberOfCharacters;
- c=getchar();
- if(c!=' '&&c!='\n'&&c!='\t')
- {
- ++NumberOfCharacters;
- }
- if(c==' '||c=='\n'||c=='\t')
- {
- break;
- }
- }
- ++nchar[NumberOfCharacters-1];
- NumberOfCharacters=0;
- }
- for(i=0;i<10;++i)
- {
- printf("%d:",i+1);
- for(Counter=1;Counter<=nchar[i];++Counter)
- {
- if (nchar[i]!=0)
- {
- printf("*");
- }
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement