Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose we flip a coin repeatedly, and we want to count the number of flips that showed heads until the first tail was found. For

Suppose we flip a coin repeatedly, and we want to count the number of flips that showed heads until the first tail was found. For example, suppose we flipped a coin 10 times, and we got H, H, H, T, H, H, T, T, T, H, where H means heads and T means tails. In this case, the number of heads before the first tail would be 3. Write a MATLAB function called heads with one input and one output, where the input is a string with 'H' for heads and 'T' for tails, and the output is the number of heads until the first tail is found. For convenience, you can assume that the input will have at least one 'T' in it, so that your program can loop through the input elements until a 'T' is found without worrying about going past the end of the input string. For example, if the input is 'HHHTHHTTTH', then the output should be 3. Although there are ways to write this function without a while loop, use a while loop in your function because the point of this problem is to practice using while loops.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions