Advertisement
lnsee96

Ex 1-13

Aug 3rd, 2016
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Write a program to print a histogram of the lengths of words in its input.
  2.   It is easy to draw the histogram with the bars horizontal; a vertical orientation is more challenging.*/
  3.  
  4.  
  5. #include <stdio.h>
  6. main()
  7. {
  8.     int c,i,NumberOfCharacters=0,Counter;
  9.     int nchar[10];
  10.     for(i=0;i<10;++i)
  11.     {
  12.          nchar[i]=0;
  13.     }
  14.     while ((c=getchar())!=EOF)
  15.     {
  16.         while(c!=' '&&c!='\n'&&c!='\t')
  17.         {   ++NumberOfCharacters;
  18.             c=getchar();
  19.             if(c!=' '&&c!='\n'&&c!='\t')
  20.                 {
  21.                     ++NumberOfCharacters;
  22.                 }
  23.             if(c==' '||c=='\n'||c=='\t')
  24.                 {
  25.                     break;
  26.                 }
  27.         }
  28.  
  29.         ++nchar[NumberOfCharacters-1];
  30.         NumberOfCharacters=0;
  31.  
  32.     }
  33.     for(i=0;i<10;++i)
  34.     {
  35.         printf("%d:",i+1);
  36.         for(Counter=1;Counter<=nchar[i];++Counter)
  37.         {
  38.             if (nchar[i]!=0)
  39.             {
  40.                 printf("*");
  41.             }
  42.         }
  43.         printf("\n");
  44.     }
  45.  
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement