Dice rolling outcomes
/* title: DiceRolling author: aeriqusyairi date: Jan26 2012 */ #include<stdio.h> #include<stdlib.h> #define ROLL 36000 int rollDice( void ); void printFreq( const int b[], int size ); int main(){ int freq[ 13 ] = { 0 }; int i, x; for(i = 0; i < ROLL; i++){ x = rollDice(); ++freq[ x ]; } printFreq( freq, 13 ); system("pause"); return 0; } int rollDice( void ){ return ( 1 + (rand() % 6) ) + ( 1 + (rand() % 6) ); } void printFreq( const int b[], int size ){ int i; for(i = 2; i < size; i++){ printf("%d occured %d times.\n", i, b[ i ] ); } }
No comments:
Post a Comment