Starting from:

$30

CPT121-Task 2.1.3 Repetition Solved

1.    Write for loops / nested for loops to print the following.

a)  1 2 4 5 7 8 10 11 ... 98 100

(numbers from 1 to 100 which are not a multiple of 3)

b)  1 2 3 ... 9     10 2 4 6 ... 18 20 3 6 9 ... 27 30

...

10 20 30 ... 90 100

 

c)  54321

5432

543

54

5

 

d)  *

**

***

****

*****

2.    Write a program which repeatedly prompts the user to enter final course results (integer values in the range 0 - 100), until the user enters a value of -1 to signal the end of their input sequence.

Once the user has finished entering input the program should display the lowest and highest results, as well as the average result across the set of results that were entered.

Note that you should not need to use an array or any other storage structure to store individual course results entered by the user, but you will need to consider which form of loop is best suited to this task and where the calculation or determination of the figures noted above will need to be done.

3.    Write a program which prompts the user to enter a name and then, using a suitable repetition structure, gives a (second) user up to five (5) attempts to guess the name that was entered previously.

For each guess the program should display the number of letters that are correct in the guess (eg. if the name is Johnathan and the user enters “Johnny” then the program should display that 4 out of 9 letters were guessed correctly).

If the user guesses the name correctly on or before the fifth attempt then they win the game, otherwise they have lost the game.  The program should display a suitable message in both scenarios (ie. win or lose) once the game has finished.

More products