diff options
author | sinanmohd <pcmsinan@gmail.com> | 2022-06-04 12:11:15 +0530 |
---|---|---|
committer | sinanmohd <pcmsinan@gmail.com> | 2022-06-04 12:11:15 +0530 |
commit | c24973af02bc33f2f5f25d37e22ca91da5de3c47 (patch) | |
tree | 460a005b6a3a9a967bd881bc2bf01e0becbe33cc /1.13.c |
inital commit
Diffstat (limited to '1.13.c')
-rw-r--r-- | 1.13.c | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -0,0 +1,50 @@ +#include <stdio.h> + +#define MAX_LEN 10 + +// Programm to produce histogram based on the length of words + +int +main() +{ + int i, j, input, word_len, big_words; + int len[MAX_LEN]; + + word_len = big_words = 0; + for (i = 0; i< MAX_LEN; i++) + len[i]=0; + + while ((input = getchar()) != EOF) { + if(input == ' ' || input == '\n' || input == '\t') { + if (word_len >= MAX_LEN) + big_words++; + else + len[word_len]++; + word_len = 0; + } + else + word_len++; + } + + if(input != ' ' && input != '\n' && input != '\t') { + if (word_len >= MAX_LEN) + big_words++; + else + len[word_len]++; + } + + printf("\n"); + + for (i = 0; i< MAX_LEN; i++) { + printf(" %d -- %3d: ", i, len[i]); + for (j =0; j < len[i]; j++) + printf("*"); + printf("\n"); + } + + printf(">%d -- %3d: ", (MAX_LEN-1), big_words); + for (j =0; j < big_words; j++) + printf("*"); + printf("\n"); +} + |