1
0
mirror of https://github.com/krislamo/knrc.git synced 2024-09-19 21:00:35 +00:00

Exercise 1-13. Vertical histogram

This commit is contained in:
Kris Lamoureux 2021-11-20 02:40:30 -05:00
parent 04ac11bea1
commit f232d42ece
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925

View File

@ -6,11 +6,10 @@
int main() int main()
{ {
int c, i, j, state, count, top;
int c, i, j, state, count;
int wordl[100]; int wordl[100];
count = state = OUT; count = state = top = OUT;
for(i = 0; i < 100; ++i) for(i = 0; i < 100; ++i)
wordl[i] = 0; wordl[i] = 0;
@ -34,13 +33,23 @@ int main()
else if (count >= 100) else if (count >= 100)
printf(MAXERROR, count); printf(MAXERROR, count);
for (i = 0; i < 100; ++i)
if (wordl[i] > top)
top = wordl[i];
printf("\n"); printf("\n");
for (i = 0; i < 100; ++i) { for (i = 0; i < 100; ++i)
if (wordl[i] > 0) { if (wordl[i] > 0)
printf("%2d | ", i); printf("%2d ", i);
for (j = 0; j < wordl[i]; ++j)
printf("#"); printf("\n");
printf("\n"); for (i = 1; i <= top; ++i) {
for (j = 0; j < 100; ++j) {
if (wordl[j] >= i)
printf(" # ");
else if (wordl[j] > 0)
printf(" ");
} }
printf("\n");
} }
} }