by Anonymous on January 26th, 2005

Anonymous

Question

Help answer this question below.

How can I write a program to create a histogram in C?

Answers. 1 helpful answer below.

  • by Quirkie on January 26th, 2005

    Quirkie

    That depends a little on what form your data takes.
    The simplest case is if you have a collection of small valued integers in the range 0..N-1 to find the histogram of.
    Create an array int count[N];
    Ensure each element in the array is zero.
    For each input integer item, ++count[item];
    Print out the array, e.g. for(item=0;item<N;++item) printf("item %d, frequency %d n",item,count[item]);

    If you have more complex items like English words in a book to find the histogram of, you need a data structure with elements containing an item and a count. Search the data structure for item and increment its count. If it's not there, add it as a new item with count one.
    There isn't space here to go into various data structures and algorithms.
    Below find a link which includes an implementation of a linked list and how to search through it:

    http://www.cprogramming.com/tutorial/lesson15.html

    • Like
    • Report

    No comments. Post one | Permalink

Want to attach an image to your answer? Click here.

Did this answer your question? If not, then ask a new question or create a poll.

You're reading How can I write a program to create a histogram in C?

Follow us on Facebook!

Related Ads

ANSWERBAG BUZZ

Histogram c
Histogram in c
C histogram
Histogram code in c
Histogram program in c