Example histogram
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <stdio.h> #include <time.h> #define MAXIMUM 30 int main (int argc, char** argv) { int _Array[MAXIMUM] = { 0, }; int Ranges[4][MAXIMUM] = { 0, }; // random (void) srand ((unsigned int) time ((char) 0)); int Range_Count[4] = { 0, }; int index = 0, _index = 0; for (index = 0; index < MAXIMUM; index++) { int Random_Number = rand() % 100 + 1; _Array[index] = Random_Number; _index = Range_Count[(int)(Random_Number / 25.001f)]++; Ranges[(int)(Random_Number / 25.001f)][_index] = Random_Number; } // print for (index = 0; index < MAXIMUM; index++) { printf ("%d\n", _Array[index]); } // histogram printf ("*** histogram (step size 25) ***\n"); int level = 0, range = 0; for (level = 0; level < 4; level++) { for (range = 0; Ranges[level][range] != 0 && range < MAXIMUM; range++) { printf ("%4d", Ranges[level][range]); } printf ("\n"); } return 0; } | cs |
0 개의 댓글:
댓글 쓰기