Advertisement
DrAungWinHtut

dice.c

Mar 23rd, 2023
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h> //srand() rand()
  3. #include<time.h> //time()
  4.  
  5. int main()
  6. {
  7.     printf("%d\n", (int)time(NULL));
  8.     int freq[7] = { 0 };
  9.     srand(time(NULL));
  10.     for (int i = 0; i < 10000; i++)
  11.     {
  12.         int dice = rand() % 6 + 1;
  13.         printf("%d ", dice);       
  14.         ++freq[dice];
  15.         if ((i+1) % 60 == 0)
  16.         {
  17.             printf("\n");
  18.         }
  19.     }
  20.     printf("\n\nNumber\tFrequency\tBargraph\n");
  21.     for (int k = 1; k <= 6; k++)
  22.     {
  23.         printf("%d\t%d\t", k, freq[k]);
  24.         for (int j = 0; j < (freq[k]/100); j++)
  25.         {
  26.             printf("*");
  27.         }
  28.         printf("\n");
  29.     }
  30.    
  31.     return 0;
  32. }
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement