Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. // EE231002 Lab05.Blackjack probabilities
  2. // 105070032, Pan_Mei_Juan
  3. // 20191014
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. int main(void)
  9. {
  10.     int k, sum = 0, i, Points;
  11.     int Runtimes = 1000;
  12.     float  CardSum = 0, YesSum = 0;
  13.  
  14.     k = rand()%13 + 1;
  15.     if (k < 11) {
  16.         if ((k == 1)&&(sum <= 21)) k = 11;
  17.         else k = k;
  18.     } else {
  19.         k = 10;
  20.     }
  21.  
  22.     printf("Points  Probability  #Cards\n");
  23.  
  24.     for (Points = 4; Points <= 21; Points++){
  25.         for (i = 0; i < Runtimes; i++){
  26.             if (sum < Points){
  27.                 sum += k;
  28.                 CardSum++;
  29.             }else if(sum == Points){
  30.                 YesSum++;
  31.             }
  32.         }
  33.         printf("%4d   %8.2f%%   %7.2f\n", Points, (YesSum/Runtimes), (CardSum/YesSum));
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement