Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C program only (Not C++ or C#) I have a coin that is notoriously not random. Every time I flip the coin its result is

C program only (Not C++ or C#)
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 < 100), representing the number of friends I have. The input will have n lines remaining lines, the i-th of which will contain a positive integer ai representing the number of times my i-th friend has asked me to flip my coin. 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. student submitted image, transcription available below 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. Reading from standard input Writing to standard output Reading in all of the values Program will be tested on 10 test cases
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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

=+ If you or someone you know is on the autism spectrum,

Answered: 1 week ago

Question

What are the primary elements of market structure?

Answered: 1 week ago