Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a coin that is notoriously not random. Every time I flip the coin its result is the opposite of the previous result. To

I have a coin that is notoriously not random. Every time I flip the coin its result is the opposite of the previous result. To prove to my friends how unfair the coin is I will flip it for them some number of times. Sadly, my friends dont care about the coins individual outcomes, only the number of heads or tails in a sequence. Each of my friends will tell me a number of times to flip the coin. I must tell them the number of times heads will appear prior to flipping the coin. After which, I will flip the coin the specified number of times, and if I am correct, I will convince them the coin is not fair. I need you to write a program that will tell me the number of heads that will appear. You can assume that I will not flip the coin between each demonstration. Additionally the last time I flipped the coin prior to showing my friends, I got a heads.

Problem: Write a program that given the number of friends and the number of flips for each friend output the number of heads that will appear in their sequence of coin flips.

Input Specification: The first line of input will be a non-negative integer n (n

Output Specification: For each friend output a single integer on a line by itself representing the number of times heads will appear for the each friend in the order in which they appear in input.

image text in transcribed Explanation Case 1: I have 1 friend who asks me to flip the coin 7 times. The resulting sequence will be THTHTHT. The number of heads is therefore 3. Case 2: I have 2 friends each ask me to flip the coin 3 times. The first sequence is THT. There is 1 heads. The second sequence will be HTH, so the number of heads is 2 for the second friend. Case 3: I have 3 friends the first asks for 4 flips. The result is THTH. The second friend asks for 6 flips, and the coin is THTHTH. The last friend asks for 3 flips and the sequence is THT.-

Grading Information Reading from standard input 20 points Writing to standard output 20 points Reading in all of the values 10 points Your program will be tested on 10 test cases 5 points each No points will be awarded to programs that do not compile.

Input Output Example Input ? Juliput 2

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 M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

Did you open with an issue explanation?

Answered: 1 week ago

Question

Find y'. y= |x + X (x) (x) X 1 02x+ 2x 1 O 2x + 1/3 Ex 2x +

Answered: 1 week ago