终于写出来了 哈哈
#include <stdio.h>
#include <stdlib.h>
#define N 30
int a[N];
void gen_random(int upper_bound)
{
int i;
for (i = 0; i < N; i++)
a[i] = rand() % upper_bound;
}
int howmany(int value)
{
int count = 0, i;
for (i = 0; i < N; i++)
if (a[i] == value)
++count;
return count;
}
int main(void)
{
int j;
int i, histogram[10];
gen_random(10);
for (i = 0; i < 10; i++)
histogram[i] = howmany(i);
for (i = 0;i < 10;i++ )
printf("%d ",i);
printf("\n");
/*
for (i = 0;i < 10;i++ )
printf("%d ",histogram[i]);
printf("\n");*/
for (j = 0;j <=N;j++)
{
for (i = 0;i < 10;i++)
if (histogram[i] <= j)
printf("
");
else
printf("* ");
printf("\n");
}
return 0;
}