Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define ITERATIONS 1000000
- #define NUM_OPTIONS 4
- float options[NUM_OPTIONS] =
- {
- 0.25,
- 0.5,
- 0.6,
- 0.25
- };
- int main(int argc, char *argv[])
- {
- int numCorrectGuesses = 0;
- int i;
- for(i=0;i<ITERATIONS;i++)
- {
- int guess = rand()%NUM_OPTIONS;
- int optioni;
- int numMatches = 0;
- for (optioni=0;optioni<4;optioni++)
- {
- if (options[optioni] == options[guess])
- numMatches++;
- }
- if (((float)numMatches / 4.0) == options[guess])
- numCorrectGuesses++;
- }
- printf("Guessed correctly %f\n", (float)numCorrectGuesses / (float)ITERATIONS);
- return 0;
- }
Add Comment
Please, Sign In to add comment