The following program in C draws a horizontal , frequency distribution , histogram for the various characters as present in the input text , except the 'space' character.
CAUTION : As i have declared variables within the beginning for loop parentheses , hence , Please compile the following program in C99 mode.If you are on Linux/Unix then you may compile it in C99 mode by typin “ -std=gnu99” or “ -std=c99 “.
Program follows :
Sample Output
CAUTION : As i have declared variables within the beginning for loop parentheses , hence , Please compile the following program in C99 mode.If you are on Linux/Unix then you may compile it in C99 mode by typin “ -std=gnu99” or “ -std=c99 “.
Program follows :
/*Program in C to print a horizontal histogram of the frequencies of different characters(except 'space') in its input*/ #include<stdio.h> int main(){ int i,j; char text[1000]; char characters[128]; for(i=0;i<=127;++i){characters[i]=0;} printf("Enter the text hither : \n"); scanf("%[^\n]",text); i=0; while(text[i]!='\0'){ j=text[i]; characters[j]=characters[j]+1; ++i; } printf("THe frequency distribution Histogram of alphabats :\n"); i=0; printf("Alphabat\n"); for(;i<=127;++i){ if((characters[i]!=0)&&(i!=32)){ printf(" %c | ",i); for(int k=1;k<=characters[i];++k){printf("#");} printf("\n"); } } printf(" --------------------------------\n"); printf(" 1 5 10 15 20 30 \n"); return 0; }
Sample Output
No comments:
Post a Comment