help with homework
I have to write a program of a vertical histogram of the letters of the alphabets.It should be like
* * *
* * * *
* * * *
a b d f
so far i have been able to calculate the frequency of the letters in the text but i have no idea as to how to print them vertically can anyone plz tell me how to do it
# include <stdio.h>
for (i = 0; i < 26; i++)
ar[i] = 0;
while ((c = getchar()) != EOF)
if (c >= 'a' && c <= 'z')
++ar[c - 'a'];
When you're printing row n, how do you know whether to print a * in column m?
You'll need to go through all the data values, and discover the minimum and the maximum values for your chart. Also, you need a tally for each letter.
Looks like you intend to use an array of int's to hold the tally's, with perhaps a representing A, a = B, etc.
Max - min in the data, will be the scale you need to represent with stars. You also need to get the page height and width, and the number of bars you need to represent. These last things you can "hard code" right into your program with define statements:
If you have a max of say 15, and a min of 1, then your scale is 14, which will fit inside 20. If your max is 50, then we'd represent it so every third letter, earned it one more star up the chart:
#define pagehi 20 //note no semi-colon on these lines
#define pagewide 26
pagehi (20) = (max - min)/x where x is the number of values that will be represented per star.
So 20x = max - min
max - min/20 = x
49/20 = x
2.45 = x
We can't print up 45% of a star, so we'd have to stick with the largest integer, 2.
That should give you a kickstart. Remember, your program has to get the tally for each letter, and save that tally, and all the letter tally's, before it can start to compute what to use for the histogram values.
Don't print anything, until everything has been calculated.