forked from steven-schronk/C-Programming-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex_1-13.c
More file actions
40 lines (32 loc) · 737 Bytes
/
ex_1-13.c
File metadata and controls
40 lines (32 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
main()
{
int c, i, j, nwhite, nother, maxnum;
int ndigit[10];
maxnum = 0;
nwhite = nother = 0;
for(i = 0; i < 10; i++)
ndigit[i] = 0;
while ((c = getchar()) != EOF)
if(c >= '0' && c <= '9')
++ndigit[c-'0'];
else if (c == ' ' || c == '\n' || c == '\t')
++nwhite;
else
++nother;
/* print out histogram */
for(i = 0; i <= 10; ++i)
{
if(ndigit[i] > maxnum) { maxnum = ndigit[i]; }
}
for(i = 0; i < maxnum; ++i) // one row for each instance of number
{
printf("%d\t|", maxnum-i); // print sidebar
for(j = 0; j <= 10; ++j) // one column for each number
{
if(ndigit[j] >= maxnum-i) { putchar('*'); } else { putchar(' '); }
}
printf("\n");
}
printf("\t 0123456789\n");
}