Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************************************************************************************************************************************
- Write a program to print a histogram of the frequencies of different characters of input.
- NOTE : we only consider alphanumeric characters here
- ************************************************************************************************************************************************************/
- #include<stdio.h>
- #include<ctype.h>
- int main (int agrc, char * argv[]) {
- int CHARACTERS [37];
- int i,c,k,a,j;
- for (i = 0; i <= 36; i++)
- CHARACTERS[i] = 0;
- while ((c = getchar()) != EOF) {
- if (isdigit(c)) {
- k = c -22;
- CHARACTERS[k]++;
- }
- else if (isalpha(c)) {
- a = tolower(c);
- k = a - 'a';
- CHARACTERS[k]++;
- }
- }
- printf("\nFrequency of occurence\n\n");
- for (i = 60; i >= 1; i--) {
- printf("%d\t| ",i);
- printf(" ");
- for (j = 0; j <= 36; j++) {
- printf(" ");
- if (CHARACTERS[j] >= i) {
- printf("*");
- }
- else {
- printf(" ");
- }
- }
- printf("\n");
- }
- printf("\t");
- for (i = 0; i < 120; ++i) {
- printf("-");
- }
- printf("\n\t\ta b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9\n\n");
- printf("\tCHARACTERS\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement