Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6.  
  7. int flip_coin(void)
  8. {
  9. return (rand() %2)?0:1;
  10. }
  11.  
  12. int flip_coin(void);
  13. int main(void)
  14. {
  15. srand(time(NULL));
  16. int result[100];
  17. for (int i=0; i<100; i++)
  18. {
  19. result[i]=flip_coin();
  20. }
  21.  
  22. int tails=0,heads=0;
  23. for (int i=0; i<100; i++)
  24. {
  25. if (result[i]==1)
  26. tails++;
  27. else
  28. heads++;
  29. }
  30. fprintf(stderr, "Heads: %d (%.2f\%)\n Tails: %d (%.2f\%)\n", heads, (double)heads,tails,(double)tails);
  31.  
  32. return 0;
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement