-
-
#include<stdlib.h> #include<stdio.h> #define N 100 int array[N]; void get_random(int upper) { int i; for(i=0; i<N; i++) array[i] = rand() % upper; } int howmany(int value) { int i, count; count = 0; for(i=0; i<N; i++) if(array[i] == value) count++; return count; } void print_pic(int level_count, int *each_count) { int i; printf(" "); if(level_count == 0) { for(i=0; i<10; i++) printf("%d ", i); printf("\n"); } else { for(i=0; i<10; i++) { if(*(each_count+i) > 0) { printf("* "); each_count[i]--;//*(each_count+i) is constant, so it can't be lvalue. each_count[i] is variable. } else printf(" "); } printf("\n"); } } int main() { int i, count[10], max; get_random(10); for(i=0; i<10; i++) count[i] = howmany(i); max = count[0]; for(i=1; i<10; i++) if(max < count[i]) max = count[i]; for(i=0; i<max; i++) print_pic(i, count); }