Guest User

Untitled

a guest
Jan 18th, 2021
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. const int NUM_OF_FACES = 6;
  6. const int NUM_ROLLS = 10000;
  7.  
  8. int main() {
  9.     int timeFacesAppeared[NUM_OF_FACES] = { 0 };
  10.    
  11.     srand(time(NULL));
  12.     for (int i=0; i<NUM_ROLLS; i++) {
  13.         int roll = rand() % NUM_OF_FACES + 1;
  14.         timeFacesAppeared[roll - 1]++;
  15.     }
  16.    
  17.     for (int face=1; face<=NUM_OF_FACES; face++) {
  18.         printf("%d appeared %d times\n", face, timeFacesAppeared[face-1]);
  19.     }
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment