Professional Documents
Culture Documents
C Programming Coursework 1
C Programming Coursework 1
int main () {
int n, throws [6];
This is the main function where the program execution starts. It declares two variables
n and throws. n will store the number of faces on the dice, and throws is an array to
store the generated throws
srand(time(0));
This seeds the random number generator. The srand function is given the current time
(in seconds since the epoch) as a seed, ensuring a different sequence of random numbers
on each program run.
return 0;
}
void generate_throws(int n, int throws[n]) {
for (int i = 1; i <= throws[0]; i++) {
This statement indicates the successful execution of the program. The value 0 is conventionally
returned to the operating system to indicate that the program terminated without errors.
This is the beginning of the generate_throws function. It takes the number of faces (n)
and the array to store throws (throws). The function uses a loop to generate random
throws and store them in the throws array.
This generates a random face value between 1 and n using the rand function.