sheyshya1

probability of finding 3 or 6 or 9 head

Mar 29th, 2022 (edited)
215
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 1
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. int main()
  5. {
  6. int j,count=0,limit,i=0,head,tail;
  7. float y,answer,h=2.5;
  8.  
  9. printf("enter the limit amount");
  10. scanf("%d",&limit);
  11. //drawing head in head tails either 3 6 or 9 times
  12. while(i<=limit)
  13. {
  14. i++;
  15. head=0;
  16. tail=0;
  17. //toss 10 times
  18. for(j=0;j<10;j++)
  19. {
  20.     //random number generated
  21. y=(float)((rand()% 65535)/65535.0f)*10;
  22. printf("%f\n",y);
  23. //head if y <2.5
  24. if (y<h)
  25. {
  26. head=head+1;
  27. }
  28. else
  29. {
  30.  
  31. tail=tail+1;
  32. }
  33. }
  34. //check prpob
  35. if ((head==3) || (head==6) || (head==9))
  36. {
  37. count=count+1;
  38. }
  39. }
  40. answer=(float)count/limit;
  41. printf("the limit is= %d \n and the probability is = %f",limit,answer);
  42. return 0;
  43.  
  44. }
  45.  
Add Comment
Please, Sign In to add comment