4) PE 05b_04 (Roll Two Dice) Write a function that generates a random number sim
ID: 3905961 • Letter: 4
Question
4) PE 05b_04 (Roll Two Dice) Write a function that generates a random number simulating the roll of two six-sided dice. The function should take no arguments and return a random number simulating a single roll of two six-sided dice. Test the function in a simple loop and print at least 25 iterations to the screen. 5) PE 05b 05 (Coin Toss) Write a function that simulates flipping a coin. The function should take no arguments and return a 0 or 1. Test the function using a simple loop in a program and print to the screen "heajis" or "tails."Explanation / Answer
#include #include #include int flip() { return rand() % 2; } int main() { srand(time(NULL)); int i; for(i = 0; i < 10; ++i) { if(flip() == 0) { printf("heads "); } else { printf("tails "); } } return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.