1) Consider the following program that flips a coin 100 times.

/* Program to simulate the flipping of the coin 100 times */

#include <stdio.h>

#include <stdlib.h>

enum CoinFace { HEADS, TAILS }; // Create an enumerated type for an integer set of named constants

enum CoinFace FlipCoin ( );

int main( ) {

enum CoinFace coin;

int count;

int headsCount;

int tailsCount;

srand( time(NULL) ); // seed/initialize the random number generator

headsCount = 0;

tailsCount = 0;

for ( count = 1; count <= 100; count++) {

coin = FlipCoin( );

if (coin == HEADS) {

printf("H ");

headsCount++;

} else {

printf("T ");

tailsCount++;

} // end if

if (count % 39 == 0) {

printf("\n");

} // end if

} // end for

printf("\nThe number of times heads occurred is %d\n", headsCount);

printf("The number of times tails occurred is %d\n", tailsCount);

} // end main

enum CoinFace FlipCoin ( ) {

int coin;

coin = rand() % 2;

if (coin == 0) {

return HEADS;

} else {

return TAILS;

} // end if

} // end FlipCoin

a) Write a program to roll a die 100 times and print the number of times each roll occurs.