Supplementary tasks repetition statements

8 1 0
Supplementary tasks   repetition statements

Đang tải... (xem toàn văn)

Thông tin tài liệu

1 Chapter 5 Repetition Statements A Review A 1 What do we mean “repetition” for repetition statements? Introduce at least three use contexts of repetition statements? A 2 What are differences between[.]

Chapter 5: Repetition Statements A Review A.1 What we mean “repetition” for repetition statements? Introduce at least three use contexts of repetition statements? A.2 What are differences between while statements and while statements? Give an example to illustrate the differences between them A.3 Compare while statements and for statements? Give an example to illustrate their dissimilarities and similarities A.4 Compare selection statements and repetition statements to clarify when selection statements should be used and when repetition statements should be used Give an example to illustrate their use context B Practice B.1 Write repetition statements that might be used in the solutions of the problems B.1.1 to B.1.15 in Chapter Remember to write variable declaration statements before the repetition statements if there is any variable in these repetition statements B.2 Identify all the errors in each program For those errors, make appropriate changes so that they become correct with no infinite loops After all, describe the output of each program B.2.1 B.2.2 B.2.3 B.2.4 B.2.5 B.2.6 B.2.7 B.2.8 B.2.9 B.2.10 B.3 Rewrite the following programs using while statements instead of for statements Describe what will be on screen if they are executed B.3.1 B.3.2 B.3.3 B.3.4 B.3.5 B.3.6 B.3.7 B.3.8 B.4 Write a program to ask a user to input a sequence of n numbers Calculate their total linear sum, sum of squares, and their average Display the results on screen with decimal places B.5 Write a program to compute a series of n Fibonacci numbers, n is a positive number input by a user Print the series with at most numbers on one single line on screen F(0)=F(1) = F(n) = F(n-1) + F(n-2) for n>=2 B.6 Write a program to ask a user to input a positive integer number in [1, 1000000] until a valid number is received Examine the input number and return its information as follows: B.6.1 How many digits are in the input number B.6.2 What is the biggest digit in the input number B.6.3 What is the smallest digit in the input number B.6.4 Determine if the input number is a symmetric one Several symmetric numbers are given as: 1, 11, 22, 121, 2332, 34143, 235532, … B.6.5 List all the prime numbers smaller than the input number with at most 10 prime numbers on one single line on screen How many of them? B.7 Given a matrix of positive integer numbers: NxN where N is input by a user The diagonal line contains N numbers each of which is N All the parallel lines above the diagonal line contain (N-1), (N-2), , and numbers each of which is N+1, N+2, …, and 2N-1, respectively All the parallel lines below the diagonal line contain (N-1), (N-2), , and numbers each of which is N1, N-2, …, and 1, respectively Display such a matrix on screen Any use of arrays is not allowed Matrix with N=6: N N-1 N-2 N-3 N-4 N-5 N+1 N N-1 N-2 N-3 N-4 N+2 N+1 N N-1 N-2 N-3 N+3 N+2 N+1 N N-1 N-2 N+4 N+3 N+2 N+1 N N-1 N+5 N+4 N+3 N+2 N+1 N Matrix (6x6) on screen: 10 11 10 B.8 Given a following menu about calculation of two positive integer numbers: What you want with your numbers? x + y x – y x * y x / y x^y x & y x | y exit Write a program to display the aforementioned menu After that ask a user to input his/her numbers along with the operator preferred If a user would like to close the program, guide them to input “-1 $ -1” to end the execution of the program Perform the calculation he/she enters and print the result “x operator y = …” on screen and then ask him/her if he/she want to continue or close the program and so on B.9 Write a program to compute an approximate value of each following function with N and x input by a user Range of x is given as: R=1, i.e x in [0, 1], R=, i.e x in R If N is given then n is from to Display the result with N and x on screen B.10 Check your coding style with the programs you have written Should anything be changed with your programs so that they can be not only executable but also readable? Rewrite your programs if yes

Ngày đăng: 11/04/2023, 18:48

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan