fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<time.h>
  4.  
  5. int main() {
  6. srand(time(0));
  7. int head_count=0, tail_count=0,x,total_toss=1000;
  8. for(int i = 0; i<total_toss; i++) {
  9. //printf(" %d ", rand()%2);
  10. x=rand()%2;
  11. if(x%2==0){
  12. head_count++;
  13. }
  14. else{
  15. tail_count++;
  16. }
  17. }
  18.  
  19. printf("Probability of getting head %f \n",((float)head_count/(float)total_toss));
  20. printf("Probability of getting tail %f",((float)tail_count/(float)total_toss));
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 4588KB
stdin
Standard input is empty
stdout
Probability of getting head 0.503000 
Probability of getting tail 0.497000