Write a C program that reads integer values from stdin, separated by one or more spaces or newlines, until reaching EOF.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 12E: (Program) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question

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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr