Lab Exercises Week 5 -8 Questions 1-5 Loops and Selection 1. Design (DSD) ,code and test a program to allow the user to input what times table he requires and display it like: What table? 12 12 TIMES TABLE 1 * 12 = 12 2* 12 = 24 . . 12 * 12 = 144 (Use a for loop for to display the table) 2. Now modify the program in 1) to validate that the user is inputting a number between 1 and 500.If not, show an error message and make the user re-input . Design,code and test. 3. Now modify the program in 2) to allow the user to keep making requests for times tables until he enters a zero. (Input would look like ‘What table (enter 0 to quit)? ‘) 4. Your times table is so popular you decide to produce a general one like below: 1| 2|
2| 4|
3| 6|
4| 8|
24|
36|
48|
5| 6| 7| 8| 9| 10| 11| 12 10| 12| 14| 16| 18| 20| 22|
24
.... 12|
60| 72|
84|
96| 108| 120| 132| 144
Use nested for loops to do this 5. Now modify 4) so it asks the user to input what times table to start from (minimum of 1) and what to finish on (max of 500). Also halt the display every 12 lines. Design, code and test. Questions 6 -7 One dimensional Arrays 6. Design, code and test a program that a) fills a 20 element array (marks) with random numbers between 0 and 100. b) Prints the numbers out 8 to a line c) Prints out the biggest number, the smallest number and the average of the numbers 7. Design, code and test a program which reads alphabetic lower case characters entered from the keyboard into an 80 character array. Input is terminated by
the user entering a ‘*’. You are required to print out a table of how many times each of the 26 letters in the alphabet occurred. Question 8 – 2 dimensional array
8. Design, code and test a program that declares a 3-by-5 array and initialise it to some values of your choice. Have the program print the values, double all the values and then display the new values.