I just handed in an assignment like this last week for my programming in c class. It's just a simple histogram.

Code:

void histogram(double input[],double range, double max, double min,char fname[], int n)
{
double storage_bins[22];
double factor;
double top;
double bottom;
double increment;
double top2 ;
double minimum;
double scale;
double cur_value;
double stars_to_print;
int i;
int j;
int max_hist;
int line;
int sum = 0;
system("cls");
factor = factor_function(range);
top = ceil(max*factor)/factor;
top2 = top;
bottom = floor(min*factor)/factor;
increment = (top-bottom)/10.;
printf("Histogram for %s\n", fname);
/* 1. Find the number of occurances of a file between certain ranges*/
minimum = top - increment/2.;
for(i = 0; i < 22; i ++)
{
if(i == 0)
{
for(j = 0; j < n; j++)
{
if(input[j] == top2)
sum +=1;
}
storage_bins[i] = sum;
}
else
{
for(j = 0; j <n; j ++)
{
if(input[j] <= top2 && input[j] > minimum)
{
sum += 1;
}
storage_bins[i] = sum;
}
top2 = top2 - increment/2.;
minimum = minimum - increment/2;
}
sum = 0;
}
/* 2. Calculate the number of stars to print for each bin*/
max_hist = storage_bins[0];
for (i=1; i<22; i++)
{
if(storage_bins[i]>max_hist)
max_hist = storage_bins[i];
}
scale = max_hist/60.;
for (line=0; line<21; line++)
storage_bins[line] = storage_bins[line]*scale +.5;
/* 3. Print the Histogram and the stars. */
for(line=1, cur_value=top; line<= 21; line++, cur_value-=increment/2.)
{
//if line is odd, print the current value.
if(line%2)
printf("%f\t", cur_value);
else
//if line is even don't print a value. shows a space
printf("\t\t");
//prints the vertical line
printf("| ");
//calculates how many stars to print for the data in the current range
stars_to_print = storage_bins[line-1] * scale;
//prints stars
for(i=0;i < stars_to_print; i ++)
printf("*");
printf("\n");
}
printf("press any key to continue...");
getche();
}

hope this helps