fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define NUM 100
  6. #define POW2(x) ((x)*(x))
  7.  
  8. int main(void)
  9. {
  10. int i;
  11. int result[NUM] = {0};
  12. srand(main);
  13.  
  14. for (i=0; i<1000000; i++)
  15. {
  16. result[ (int) sqrt( rand()%POW2(NUM) )]++;
  17. }
  18.  
  19. for (i=0; i<NUM; i++)
  20. {
  21. printf("arr[%d] = %d\n", i, result[i]);
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0.07s 1676KB
stdin
Standard input is empty
stdout
arr[0] = 92
arr[1] = 311
arr[2] = 505
arr[3] = 687
arr[4] = 835
arr[5] = 1114
arr[6] = 1317
arr[7] = 1535
arr[8] = 1780
arr[9] = 1822
arr[10] = 2115
arr[11] = 2322
arr[12] = 2400
arr[13] = 2666
arr[14] = 2957
arr[15] = 3180
arr[16] = 3317
arr[17] = 3482
arr[18] = 3649
arr[19] = 3897
arr[20] = 4201
arr[21] = 4310
arr[22] = 4501
arr[23] = 4635
arr[24] = 4930
arr[25] = 5146
arr[26] = 5360
arr[27] = 5554
arr[28] = 5809
arr[29] = 5666
arr[30] = 6174
arr[31] = 6235
arr[32] = 6331
arr[33] = 6794
arr[34] = 6792
arr[35] = 7126
arr[36] = 7251
arr[37] = 7561
arr[38] = 7661
arr[39] = 7907
arr[40] = 8067
arr[41] = 8360
arr[42] = 8483
arr[43] = 8637
arr[44] = 8719
arr[45] = 9107
arr[46] = 9428
arr[47] = 9392
arr[48] = 9668
arr[49] = 9935
arr[50] = 9979
arr[51] = 10282
arr[52] = 10460
arr[53] = 10797
arr[54] = 10863
arr[55] = 11133
arr[56] = 11380
arr[57] = 11441
arr[58] = 11636
arr[59] = 11962
arr[60] = 11981
arr[61] = 12128
arr[62] = 12558
arr[63] = 12558
arr[64] = 12858
arr[65] = 12992
arr[66] = 13385
arr[67] = 13600
arr[68] = 13798
arr[69] = 13764
arr[70] = 14135
arr[71] = 14284
arr[72] = 14329
arr[73] = 14698
arr[74] = 14976
arr[75] = 15320
arr[76] = 15622
arr[77] = 15415
arr[78] = 15671
arr[79] = 15869
arr[80] = 16044
arr[81] = 16457
arr[82] = 16851
arr[83] = 16719
arr[84] = 16726
arr[85] = 17061
arr[86] = 17312
arr[87] = 17549
arr[88] = 17897
arr[89] = 17774
arr[90] = 17954
arr[91] = 18276
arr[92] = 18526
arr[93] = 18818
arr[94] = 18979
arr[95] = 18823
arr[96] = 19456
arr[97] = 19571
arr[98] = 19762
arr[99] = 19848