Untitled
unknown
plain_text
3 years ago
773 B
3
Indexable
#include <stdio.h> #include <stdlib.h> #include <time.h> #define SIZE 12 #define ITERATIONS 36000 int main() { int Dice, Dice2, Dice_total, Roll, Results[ITERATIONS], frequency[SIZE+1]={0}, Tot=0; srand(time(NULL)); for(Roll = 0; Roll < ITERATIONS; Roll++) { Dice = rand() % 6 + 1; Dice2 = rand() % 6 + 1; Dice_total = Dice + Dice2; Results[Roll] = Dice_total; } for(Dice = 0; Dice < ITERATIONS; Dice++) ++frequency[Results[Dice]]; printf("%s%17s\n", "Total", "Frequency"); for(Dice = 0; Dice < SIZE; Dice++) { printf("%4d%17d\n", Dice + 1, frequency[Dice + 1]); Tot += frequency[Dice + 1]; } printf("\nTotal values:%i\n", Tot); return 0; }
Editor is loading...