Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Exercise 1-14. Write a program to print a histogram of the frequencies of different characters in its input.*/
- #include <stdio.h>
- #define INDEX 27
- int main()
- {
- int histog[INDEX], c;
- for (c = 0;c < INDEX; c++)
- histog[c] = 0;
- while ((c = getchar()) != EOF) {
- switch (c) {
- case 'a': ++histog[0];
- break;
- case 'b': ++histog[1];
- break;
- case 'c': ++histog[2];
- break;
- case 'd': ++histog[3];
- break;
- case 'e': ++histog[4];
- break;
- default : ++histog[26];
- }
- }
- printf ("char histogram are histog[a] = %d\n", histog[0]);
- printf ("char histogram are histog[b] = %d\n", histog[1]);
- printf ("char histogram are histog[c] = %d\n", histog[2]);
- printf ("char histogram are histog[d] = %d\n", histog[3]);
- printf ("char histogram are histog[e] = %d\n", histog[4]);
- printf ("char histogram are histog[other] = %d\n", histog[26]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment