Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- int flip_coin(void)
- {
- return (rand() %2)?0:1;
- }
- int flip_coin(void);
- int main(void)
- {
- srand(time(NULL));
- int result[100];
- for (int i=0; i<100; i++)
- {
- result[i]=flip_coin();
- }
- int tails=0,heads=0;
- for (int i=0; i<100; i++)
- {
- if (result[i]==1)
- tails++;
- else
- heads++;
- }
- fprintf(stderr, "Heads: %d (%.2f\%)\n Tails: %d (%.2f\%)\n", heads, (double)heads,tails,(double)tails);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement