fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define NUM 100
  6.  
  7. int main(void)
  8. {
  9. int i, random_integer, position;
  10. int result[NUM] = {0};
  11.  
  12. for (i=0; i<1000000; i++)
  13. {
  14. /* rand() mod NUM^2 */
  15. random_integer = rand() % (NUM * NUM);
  16.  
  17. /* square root */
  18. position = sqrt(random_integer);
  19.  
  20. result[position]++;
  21. }
  22.  
  23. for (i=0; i<NUM; i++)
  24. {
  25. printf("arr[%d] = %d\n", i, result[i]);
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0.07s 1676KB
stdin
Standard input is empty
stdout
arr[0] = 109
arr[1] = 297
arr[2] = 498
arr[3] = 670
arr[4] = 890
arr[5] = 1164
arr[6] = 1295
arr[7] = 1475
arr[8] = 1666
arr[9] = 1927
arr[10] = 2079
arr[11] = 2300
arr[12] = 2468
arr[13] = 2706
arr[14] = 2962
arr[15] = 3186
arr[16] = 3298
arr[17] = 3395
arr[18] = 3594
arr[19] = 3928
arr[20] = 4038
arr[21] = 4194
arr[22] = 4525
arr[23] = 4807
arr[24] = 4836
arr[25] = 5062
arr[26] = 5385
arr[27] = 5521
arr[28] = 5730
arr[29] = 5876
arr[30] = 6027
arr[31] = 6406
arr[32] = 6616
arr[33] = 6756
arr[34] = 6856
arr[35] = 7006
arr[36] = 7306
arr[37] = 7455
arr[38] = 7608
arr[39] = 8092
arr[40] = 8080
arr[41] = 8363
arr[42] = 8514
arr[43] = 8748
arr[44] = 8880
arr[45] = 9001
arr[46] = 9165
arr[47] = 9398
arr[48] = 9732
arr[49] = 9994
arr[50] = 10240
arr[51] = 10312
arr[52] = 10519
arr[53] = 10580
arr[54] = 10938
arr[55] = 11050
arr[56] = 11253
arr[57] = 11377
arr[58] = 11730
arr[59] = 11863
arr[60] = 11991
arr[61] = 12301
arr[62] = 12481
arr[63] = 12765
arr[64] = 12914
arr[65] = 13073
arr[66] = 13145
arr[67] = 13577
arr[68] = 13730
arr[69] = 14024
arr[70] = 14140
arr[71] = 14424
arr[72] = 14409
arr[73] = 14509
arr[74] = 14890
arr[75] = 15091
arr[76] = 15243
arr[77] = 15504
arr[78] = 15757
arr[79] = 15999
arr[80] = 16208
arr[81] = 16447
arr[82] = 16618
arr[83] = 16611
arr[84] = 16938
arr[85] = 17192
arr[86] = 17439
arr[87] = 17411
arr[88] = 17501
arr[89] = 18087
arr[90] = 18332
arr[91] = 18084
arr[92] = 18520
arr[93] = 18674
arr[94] = 18788
arr[95] = 18989
arr[96] = 19381
arr[97] = 19470
arr[98] = 19599
arr[99] = 19998