Guest User

Untitled

a guest
Feb 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. #define ITERATIONS 1000000
  6. #define NUM_OPTIONS 4
  7.  
  8. float options[NUM_OPTIONS] =
  9. {
  10. 0.25,
  11. 0.5,
  12. 0.6,
  13. 0.25
  14. };
  15.  
  16. int main(int argc, char *argv[])
  17. {
  18. int numCorrectGuesses = 0;
  19. int i;
  20.  
  21. for(i=0;i<ITERATIONS;i++)
  22. {
  23. int guess = rand()%NUM_OPTIONS;
  24. int optioni;
  25. int numMatches = 0;
  26.  
  27. for (optioni=0;optioni<4;optioni++)
  28. {
  29. if (options[optioni] == options[guess])
  30. numMatches++;
  31. }
  32.  
  33. if (((float)numMatches / 4.0) == options[guess])
  34. numCorrectGuesses++;
  35. }
  36.  
  37. printf("Guessed correctly %f\n", (float)numCorrectGuesses / (float)ITERATIONS);
  38.  
  39. return 0;
  40. }
Add Comment
Please, Sign In to add comment