Bookmark and Share

Liens sponsorisés

Seniors Level 3 Print E-mail
Written by Administrator   

1. ARROWS

Write a program that will ask the user to make a choice between (U)p or (D)own and print out the corresponding arrow. (Each arrow must be generated, not stored and printed.)

Sample Run

U

*

***

*****

*******

*********

***********

*

*

*

D

*

*

*

***********

*********

*******

*****

***

*

 

2. EVEN UP

If you toss a fair coin two times, should you expect to get one head and one tail? If you toss the same coin ten times should you expect to get five heads and five tails?

To investigate this problem, write a program that will simulate the tossing of a fair coin N times (N must be even) and count the number of heads and tails. Repeat this experiment R times and summarize the results as shown below.

Test your program for N=4 , R=10 and N=10, R=20

Sample Run

Number of tosses (Even)? 4

Number of repetitions? 10

H T

HTTT 1 3

THHH 3 1

HTTT 1 3

THTT 1 3

TTTT 0 4

TTHH 2 2 EQUAL

HTTH 2 2 EQUAL

HTTT 1 3

TTHH 2 2 EQUAL

HHHH 4 0

Heads=Tails 3 out of 10 times.

 

3. SECRET CODE

You have just found the secret instructions on how to encode a message.

"Calculate the message length and round up to the nearest multiple of 5. Write out the message in rows of 5 characters each until the message is complete. Send the message a column at a time from left to right."

For example, suppose the message is THIS IS A CODED MESSAGE

It is 23 characters long, so two spaces are added at the end to make the message 25 characters long. The message is placed in rows of five characters each:

1 2 3 4 5

T H I S

I S A

C O D E D

M E S S

A G E

The characters are sent one column at a time from left to right

TIC.AHSOMGI.DEESAES...DS.

(a period indicates a space)

A coded message has just come over the wire:

TE.AAECHCMGSNOEREE..D.ES.

BDESTSHEED

Write a program that will decode any message using this coding method.

Test your program by decoding both codes shown above.


Sample Run

Enter your secret message:

? TIC AH SOMGI DEESAES DS

Decoded it reads:

THIS IS A CODED MESSAGE.

 

4. DICTIONARY ORDER

The number 79 becomes "seven nine" when translated digit by digit into a string of words. Likewise 80 becomes "eight zero." When sorted as numbers, 79 comes before 80. But as a string of words "eight zero" comes before "seven nine" in the dictionary.

Write a program that prints out the integers between 1 and 99 in Dictionary Order. Print them in rows of 10 numbers each.

Sample Run

8 88 85 84 89 81 87 86 83 82

80 5 58 55 54 59 51 57 56 53

.............................

 

5. ZERO SUM

Consider the sequence of digits from 1 through N (where N<=9) in increasing order

1 2 3 4 5 N

and insert either a (+) for addition or a (-) for subtraction in the space between each pair of digits. Now sum the result and see if you get a zero.

Write a program that will find all sequences of length N that produce a ZERO SUM.

Test your program for N=7 and N=8.


Sample Run

INPUT "ENTER A VALUE FOR N";7

THE ZERO SUMS OF LENGTH 7 ARE:

1 + 2 - 3 + 4 - 5 - 6 + 7 = 0

1 + 2 - 3 - 4 + 5 + 6 - 7 = 0

1 - 2 + 3 + 4 - 5 + 6 + 7 = 0

1 - 2 - 3 - 4 - 5 + 6 + 7 = 0

 

 

Liens sponsorisés