Write a C program that reads integer values from stdin, separated by one or more spaces or newlines, until reaching EOF.
Write a C program that reads integer values from stdin, separated by one or more spaces or newlines, until reaching EOF.
Once we have entered all our integers, we may have to press Enter before pressing Ctrl+d.
This signifies that we do not have to create a function, we can implement this vertical histogram
program within our main(...) function.
Save your program as verticalHistogram.c
-
The input contains no more than 80 values.
Why? Because a standard terminal window is 80 character-columns across. -
The input is guaranteed to be well-formed.
-
On standard output (stdout), it renders a simple vertical column graph representation of the input values (i.e., a vertical histogram), in order left to right, using hash '#' characters as shown in the examples on the next slides. The number of hashes '#' printed in each column
should be equal to the corresponding input value.
The area above a completed column should be filled with space characters.
Ignore empty lines in the input. Do not output a column for an empty line in the input.
The entire graph must end with a newline character. Hint:
In order to plot a histogram vertically, we need to have finished reading all the input before we start drawing the histogram on stdout. An array is suitable for this.
If we limit the number of columns we can graph to a maximum of 80, we know how large an array we need to allocate and this program is simple to write.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps