histogram

This is a discussion on histogram within the C Programming forums, part of the General Programming Boards category; Hey guys im trying to make a horizontal histogram how would i set my loop up so i can print ...

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    histogram

    Hey guys im trying to make a horizontal histogram how would i set my loop up so i can print
    the array out


    enter frequencies 2 5 10 4 123

    2 4 5 6 7 8 etc

    i have it printing the horizontal axis of numbers
    0 5 10 15 20 25 30 35
    +----+----+----+----+----+----++----+
    |**
    |*****
    |************
    |****
    5|**************************************


    how would i make that?

    i have already done the input of 20 integers which is stored into an array
    im pretty desperate this is due today

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The for loop, using the count of the number of integers entered as the stopper for the loop, makes a natural outer loop. Inside this for loop, try a while array element > number++..

    If the array element being looked at is > the number being compared with, then print a '*', otherwise print a newline '\n'.

    For further help, you'll need to post your code, and it's output, so we're not yakking incomprehensible nonsense, guessing.

    Adak

  3. #3
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    What you want (isn't this the 3rd or 4th thread about the same thing) is the following:

    Code:
    for (all the numbers in my array)
    {
        i = 0;
        while (i < number from my array)
        {
            i++
            print "*"
        }
        print '\n'
    }

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Two nested for loop would work quite well.

    Also see 20 integers
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a question on producing a pixel histogram of a picture
    By tracyhaha in forum C Programming
    Replies: 3
    Last Post: 04-07-2007, 07:27 AM
  2. Histogram
    By fjf314 in forum C++ Programming
    Replies: 1
    Last Post: 01-15-2004, 10:39 PM
  3. Max & Min value and refine histogram
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 07-20-2002, 08:04 AM
  4. Still can't print a Histogram from fail input
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 07-11-2002, 12:24 PM
  5. Help Me ! Print a histogram From a file
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 07-10-2002, 09:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21