a) Write a function to simulate coin tossing, the function will use rand function that gives an output 0 or 1. Then function will return 0 as Head and return 1 as Tail. b) Write a complete program in C to take a number (N) from the user and toss the coin N times using the function defined in part a), and count the number of Heads and number of Tails. Finally, print a histogram using ** for the number of Heads and Tails. For example, if the number of Heads is 5 and number of Tails is 10, the

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.4: A Case Study: Rectangular To Polar Coordinate Conversion
Problem 9E: (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question

a) Write a function to simulate coin tossing, the function will use rand function that
gives an output 0 or 1. Then function will return 0 as Head and return 1 as Tail.
b) Write a complete program in C to take a number (N) from the user and toss the coin
N times using the function defined in part a), and count the number of Heads and
number of Tails. Finally, print a histogram using ‘*’ for the number of Heads and
Tails. For example, if the number of Heads is 5 and number of Tails is 10, the
following histogram will be printed: (Hint: Use for loops for repetition and if/else
for selection of Head or Tail).
Output:
Head: 10 **********
Tail: 5 *****

Q3)
a) Write a function to simulate coin tossing, the function will use rand function that
gives an output 0 or 1. Then function will return 0 as Head and return 1 as Tail.
b) Write a complete program in C to take a number (N) from the user and toss the coin
N times using the function defined in part a), and count the number of Heads and
number of Tails. Finally, print a histogram using *** for the number of Heads and
Tails. For example, if the number of Heads is 5 and number of Tails is 10, the
following histogram will be printed: (Hint: Use for loops for repetition and if/else
for selection of Head or Tail).
Output:
Head: 10 *****
**
Tail: 5 *****
Transcribed Image Text:Q3) a) Write a function to simulate coin tossing, the function will use rand function that gives an output 0 or 1. Then function will return 0 as Head and return 1 as Tail. b) Write a complete program in C to take a number (N) from the user and toss the coin N times using the function defined in part a), and count the number of Heads and number of Tails. Finally, print a histogram using *** for the number of Heads and Tails. For example, if the number of Heads is 5 and number of Tails is 10, the following histogram will be printed: (Hint: Use for loops for repetition and if/else for selection of Head or Tail). Output: Head: 10 ***** ** Tail: 5 *****
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr