Advertisement
iocoder

Probability

Aug 10th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. unsigned char x[16] = { 1, 1, 1, 1, 1, 1,
  4.             2, 2, 2, 2, 2,
  5.             3, 3, 3, 3, 3};
  6.  
  7. unsigned int sum = 0;
  8. unsigned int a = 0, b = 0;
  9.  
  10. void rec(unsigned int i, unsigned int count) {
  11.     if (count == 3) {
  12.         if (sum == 6) a++;
  13.         b++;
  14.         return;
  15.     }
  16.     for (; i < 16; i++) {
  17.         sum += x[i];
  18.         rec(i+1, count+1);
  19.         sum -= x[i];
  20.     }
  21. }
  22.  
  23. int main() {
  24.     rec(0, 0);
  25.     printf("%d/%d=%f\n", a, b, (float) a/b);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement