fork download
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6.  
  7. #define HISTSIZE 100
  8. #define BUFSIZE 100
  9.  
  10. // 正規乱数
  11. double normrand(void)
  12. {
  13. double ra, rb, nr;
  14.  
  15. ra = (double)rand() / RAND_MAX;
  16. rb = (double)rand() / RAND_MAX;
  17. nr = sqrt(-2.0 * log(ra)) * cos(2.0 * M_PI * rb);
  18. return nr;
  19. }
  20.  
  21. int main()
  22. {
  23. int hist[HISTSIZE] = {0};
  24. char buf[BUFSIZE];
  25. double x, y, d;
  26. int i, s, h;
  27.  
  28. srand(time(NULL));
  29. memset(buf, '*', BUFSIZE);
  30.  
  31. for (i = 0; i < 1000; i++) {
  32. x = y = 0.0;
  33. for (s = 0; s < 1000; s++) {
  34. x += normrand();
  35. y += normrand();
  36. }
  37. d = sqrt(x * x + y * y);
  38. printf("%5.1f%c", d, (i+1)%10?' ':'\n');
  39. h = d;
  40. if (h < HISTSIZE) {
  41. hist[h]++;
  42. }
  43. }
  44. for (i = 0; i < HISTSIZE; i++) {
  45. h = hist[i];
  46. if (BUFSIZE < h) h = BUFSIZE;
  47. printf("%3d %3d %.*s\n", i, hist[i], h, buf);
  48. }
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.52s 2680KB
stdin
Standard input is empty
stdout
 19.9  27.9  41.0  48.2  54.3  23.6  60.0  26.1  23.3  25.9
 43.3  43.9  76.8  30.0   1.0  83.6  48.8  39.7  83.6  34.6
 45.8  41.5  32.2  12.4  29.9  54.9  40.8  54.9  33.8  47.4
 41.4  60.5   4.6  60.6  23.7  41.1  12.7  43.2  40.1  43.1
 97.3  49.9  71.6  51.5  29.6  62.5  52.9  49.2  59.5  16.6
 49.3  19.2  45.2  25.7  33.1  47.1  10.5  31.9  46.5  32.9
 34.9  31.7  19.6  45.4   4.0  37.5  42.1  35.0  51.2  45.1
 15.2  47.9  41.6  21.4  50.7  43.0  28.2  66.3  37.6  77.8
 36.6  77.6  16.6  46.6  82.5  46.1  24.4  14.2  12.8  24.5
 18.9  58.9  52.1  58.1  36.4  16.3  22.5  24.4  20.1  54.0
 17.8  29.4  43.5  54.9  84.5  11.6  52.8   7.5  34.6  19.6
 27.5  19.7  35.8  34.6   7.1  25.2  29.7  75.2  13.0  34.1
  7.7  53.5  70.8  54.5  41.1  40.7  32.7  13.4  47.3  76.8
 41.1  43.8  53.9  50.1  29.5   3.9  81.2  10.6   9.1  14.0
 43.1  55.2  33.7  17.8  71.9  34.2  16.4  45.0  16.1  40.6
100.9   9.2  23.7  32.2  55.9  22.8  40.8  63.9  23.0  78.9
 57.1  96.6  59.9  61.3  18.6   3.9  21.9  37.9  28.2  44.9
 11.8  36.9   7.6  59.5  87.9  13.4  52.6  35.2   9.7  58.5
 63.3  48.1  61.8  55.2  32.8   2.3  61.1  60.0  13.1  65.3
 29.7  52.6  39.1  21.7  39.1  55.1  33.8  19.7  59.1  41.9
 54.4  15.9  22.7   6.7  60.8  33.7  35.1  18.9  61.5  49.8
 60.0  27.9  67.1  40.6  72.4  29.8  50.2  25.1  36.1  10.4
 40.7  59.1  56.7  51.2  46.2  45.8  35.6   9.1  27.7  15.7
 46.9  36.5  64.5  63.9  15.6  47.8  48.1  27.5  34.4  26.0
 24.4  12.8  47.1  35.6  52.5  13.6  14.0  73.5  48.6  34.6
 30.7  95.0  73.6  34.4  22.7  61.3  19.9  48.9  27.1  66.5
 33.7  58.9  58.8  51.7  48.3  45.3  27.0  38.5  34.0  49.8
 51.7  62.9  56.0  22.3  40.1  44.5  52.3  68.7   8.0  50.8
 26.7  26.9  46.4  33.6  22.1  58.5  35.8  43.2  38.8  35.1
 88.2  28.6  21.3  17.9  22.0  89.3  20.6  29.7  40.2  15.7
 72.6  11.1  59.6  48.4  12.1  23.1  48.8  20.6  22.5   5.6
 21.8  39.5  81.1  59.2  21.3  82.0  61.3  30.1  93.5  35.0
 51.7  50.3  35.4  32.2  23.7  47.3  46.0  39.0  12.1  70.2
 27.1  80.4  57.3  31.4  52.3   7.9  30.3  25.6  26.7  49.9
 62.0  30.6  62.0  68.4  31.7  35.5  42.4  47.8  47.1  12.2
 21.9  37.7  18.3  19.0  73.6  32.7  19.3  34.2  52.3  11.2
 53.3  21.6  44.1  20.0  23.3   5.4  50.4  15.4  45.4  30.2
 22.8  59.1  34.4  55.8  23.8  54.3  64.4  68.4  63.6  17.7
 43.4   4.9  56.4  34.0  16.4  23.0  71.8  15.1  30.1  37.3
 54.1  28.2  46.2   2.4  63.4  10.4  45.0  27.8  64.3  57.4
 68.5  33.7  40.9  31.9  15.8  53.3  45.2  24.6  31.8  39.9
 16.6  23.9  25.7  27.9  60.0  39.6  39.4  57.9  89.9  62.7
 39.3  49.0  44.9  29.1  16.7  38.0  36.2  44.6  49.6  33.8
 60.1  45.6  19.8  23.6  50.9  33.9  85.7  22.9  41.4  28.9
 55.8  59.5  40.8  32.9  36.0  50.7  24.6  60.0  51.1  97.5
 45.0  27.7  14.6  33.6  49.0  25.8  14.3  39.0  40.6  35.8
 35.5  25.9  19.3  17.1  19.6  28.5  55.4  42.3  47.8  26.3
 42.3  29.7  43.4  13.5  28.3   5.4  57.8  39.6  54.7  50.8
 39.4  17.6  47.6  22.4  26.5  94.0  62.9  45.2  85.0   9.7
 64.6  20.1  55.9  63.0  19.9  17.4  63.1  84.3  26.4  60.1
 21.1  49.6  45.1  20.5  49.3  39.4  38.5   7.1  37.6  13.0
 80.3  44.8  54.4  25.7  60.8  41.1  61.9  40.1  44.2  41.3
 26.3  24.5  37.3  30.2  28.4 102.8  52.3  40.1  38.3  27.4
 47.7  27.8  49.6  35.7  14.0  21.1  15.6  31.4  26.7  39.9
 19.2  55.7  40.1  14.0  22.2 102.8  29.2  40.8  87.1  65.6
 39.4  51.8  45.5  17.6  51.2  43.7  31.6  46.3 102.4  37.7
  3.9  13.8  53.1  28.5  36.5  10.6  55.7  59.7  36.9  69.5
 20.7  44.7  56.0  78.2  28.8  19.3  47.1  32.8  16.9   6.6
 55.3  25.5  22.3  54.5  19.3  34.1  61.1  29.9  22.5  52.1
 32.2  16.6  45.9  33.6  37.8  36.9  81.6  50.3  15.1  29.5
 23.9  22.7  19.7  27.6   8.7  74.5  68.4  45.2  33.2  23.1
  9.5  39.4   9.0  32.6  18.4 106.1  99.3  49.2  54.5  29.9
 52.5  44.4  94.7  55.3  59.8   6.8  33.5  42.5  55.8  33.7
 16.6  54.4  30.0  44.6  24.2  46.1  21.0  34.1  25.6  50.7
 32.0  25.1  50.5  10.2  20.7  49.8  49.7  67.7  59.2  29.9
 25.3  18.2  54.4  17.4  50.7  51.2  51.2  27.7  15.3  42.2
 58.5  55.6  36.0  29.7  54.5  52.0  19.8  70.7  61.0  27.9
 38.4  70.5  19.6  31.1  25.3  39.3  44.3  11.4  35.4  75.7
 28.7  15.5  10.1  35.8  22.6  22.9  60.5  46.9  16.1  52.1
  8.8  43.1  23.8  53.3  34.2  34.6  19.4   7.4  50.8  44.1
 36.5  69.9  37.3  49.6  54.3  18.1  67.1   9.7  59.1  56.9
 12.1  16.6  76.5  33.9  31.6  44.0  32.4  41.0  21.1  64.8
 75.9  28.0  47.9   9.3  33.5  25.7  18.7  40.5  58.7  23.5
  2.9  44.9  64.6  33.8  36.9  43.0  26.0  20.9  93.8  65.5
  5.8  39.4  37.4  23.2  64.2  25.9  18.4  60.6  40.7  52.8
 58.6  62.5  43.8  36.5  34.6  17.3  47.3  41.1  12.3  34.5
 55.6  26.4  51.8  29.7  90.2  15.6  35.0  46.8  21.2  37.3
 18.9   9.2  89.2  27.8  38.0  48.7  56.3  13.2  52.8  55.5
 76.6  37.1  37.5  46.2  48.1  59.1  37.4  78.9  75.3  70.3
 79.4  48.8  33.5  34.7  23.4  42.9  19.7  52.0  25.0  23.8
 40.9  31.2  32.0  55.9  34.4  70.5  55.7  50.1  43.5  33.0
  9.5  11.3  37.2  29.8  50.7   6.0   4.3  47.3  24.6  19.1
 38.2  57.7  50.9  24.7  52.9  53.2  70.2  57.7  59.1  38.8
 29.3  53.4  22.5  44.1  32.6  29.3  10.0  56.1  37.2  72.2
  4.7  29.6  29.6  33.1  41.2  45.6   8.5  46.3  62.0  10.1
 35.3  38.9  90.9  75.4  43.6  28.2  45.2  49.8   6.3  41.7
 52.6  29.0  14.8  37.8  23.3  44.7  41.5  37.7  55.1  47.1
 33.2  26.5  32.9  72.7  36.2  31.7  36.8  12.5  37.3  43.1
 41.7  32.1  27.7  34.5  50.1  38.4  12.8  37.5  34.8  41.0
 25.3  52.9   9.6  32.6  51.4  19.8  63.5  54.3  35.1   6.0
 21.0  19.3  38.2  57.8  29.2  57.2  16.1  31.9  68.2  75.1
 34.0  41.6  18.3  34.4  32.8   9.7  22.7  22.1  39.8  57.7
 59.3  37.3  38.7  40.7   6.2   3.2  27.2  59.5  48.6   5.5
 28.0  36.3  27.1  44.0  39.9  37.6  37.7  42.3  33.3  32.7
 20.5  34.5  38.0  10.2  56.2  16.6  40.0  32.4  43.4  47.2
 39.2  27.9  19.4  25.4  46.8  72.7  21.1  96.7  25.8  75.1
 62.2  18.0  32.9  43.3  38.6  22.7  63.5  24.4  56.9  32.6
 35.9  57.8  29.5  67.8   6.4  53.6  68.0  20.1  45.2  18.0
 25.6  19.9  62.3  12.6  57.2  48.8  71.8  29.0  45.8  24.9
  8.8  48.4  38.0  11.0  38.7  31.4  33.4  40.5  48.4  16.4
  0   1 *
  1   0 
  2   3 ***
  3   4 ****
  4   5 *****
  5   6 ******
  6   7 *******
  7   7 *******
  8   5 *****
  9  14 **************
 10  10 **********
 11   6 ******
 12  14 **************
 13   9 *********
 14   6 ******
 15  13 *************
 16  16 ****************
 17  11 ***********
 18  12 ************
 19  27 ***************************
 20  11 ***********
 21  15 ***************
 22  21 *********************
 23  19 *******************
 24  12 ************
 25  21 *********************
 26  13 *************
 27  22 **********************
 28  14 **************
 29  26 **************************
 30   8 ********
 31  14 **************
 32  23 ***********************
 33  26 **************************
 34  26 **************************
 35  19 *******************
 36  16 ****************
 37  27 ***************************
 38  14 **************
 39  21 *********************
 40  24 ************************
 41  17 *****************
 42   9 *********
 43  19 *******************
 44  19 *******************
 45  20 ********************
 46  14 **************
 47  18 ******************
 48  16 ****************
 49  17 *****************
 50  18 ******************
 51  14 **************
 52  19 *******************
 53   9 *********
 54  18 ******************
 55  20 ********************
 56   8 ********
 57  12 ************
 58   9 *********
 59  19 *******************
 60  11 ***********
 61  10 **********
 62   9 *********
 63   9 *********
 64   7 *******
 65   3 ***
 66   2 **
 67   5 *****
 68   6 ******
 69   2 **
 70   7 *******
 71   4 ****
 72   5 *****
 73   3 ***
 74   1 *
 75   7 *******
 76   4 ****
 77   2 **
 78   3 ***
 79   1 *
 80   2 **
 81   4 ****
 82   1 *
 83   2 **
 84   2 **
 85   2 **
 86   0 
 87   2 **
 88   1 *
 89   3 ***
 90   2 **
 91   0 
 92   0 
 93   2 **
 94   3 ***
 95   0 
 96   2 **
 97   2 **
 98   0 
 99   1 *