Advertisement
Guest User

Untitled

a guest
Sep 10th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. #include<time.h>
  5. #define MAX(x, y) (((x) > (y)) ? (x) : (y))
  6. #define MIN(x, y) (((x) < (y)) ? (x) : (y))
  7.  
  8. int main()
  9. {
  10. int i,j,s1,s2,s,r;
  11. srand(time(NULL));
  12. for(i=0,j=0;i<1000000;i++)
  13. {
  14. s1=rand()%1000;
  15. s2=rand()%1000;
  16. s=rand()%1000;
  17. if(rand()%2==0) r=s1; else r=s2;
  18. if(r<=s && r==MIN(s1,s2)) j++;
  19. else if(r>s && r==MAX(s1,s2)) j++;
  20.  
  21. }
  22. printf("%f",(float) j/i);
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement