Course Programming Fundamentals (C language) 1 LAB 5 – Repetition Statements Main content 1 Get used to simple repetition statements 2 Get used to nested repetition statements 3 Start more complex dat[.]
Course: Programming Fundamentals (C language) LAB – Repetition Statements Main content: Get used to simple repetition statements Get used to nested repetition statements Start more complex data processing Check coding styles Practice: Get used to simple repetition statements 1.1 Write a C program to display the following number series on the screen: 1.1.1 The series has N numbers with a natural number N input by a user from keyboard N = 12: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 1.1.2 The series has N numbers with a natural number N input by a user from keyboard N = 8: 0, 2, 6, 14, 30, 62, 126, 254 1.1.3 The series has the numbers less than a natural number N input by a user from keyboard N = 500: 1, 4, 13, 40, 121, 364 1.1.4 The series has the numbers less than a natural number N input by a user from keyboard N = 20: 3, 7, 11, 15, 19 the the the the 1.2 Write a C program to process an integer number input by a user from the keyboard with the following requests: 1.2.1 How many digits are there in the given number? 1.2.2 Display the given number in a histogram as follows: 1.2.3 Calculate and return the total sum of all the odd digits in the given number 1.2.4 Calculate and return the total sum of all the digits at odd positions in the given number It is supposed that the most left digit is counted at position from the left to the right 1.2.5 Check if the number is a prime number 1.2.6 Find and print an inversed number of the given number For example: An integer number input by a user is 123456 1.2.1 There are digits in the number 123456 1.2.2 Histogram of the number 123456 is displayed below: 1: * 2: ** 3: *** 4: **** 5: ***** 6: ****** 1.2.3 The total sum of all the odd digits in the number 123456 is 1.2.4 The total sum of all the digits at odd positions in the number 123456 is 12 1.2.5 The number 123456 is not a prime number 1.2.6 An inversed number of the number 123456 is 654321 1.3 Write a C program to calculate and display a total sum of all the even numbers sequentially input by a user from the keyboard till is input Also return the number of the even numbers, the number of all the numbers, and the percentage of the even numbers over all the numbers that have been input 1.4 Write a C program to randomly generate N natural numbers in [0, 100] with a natural number N input by a user from the keyboard Calculate and display a total sum of all the odd numbers Also return the number of the odd numbers and the percentage of the odd numbers over all of N numbers that have been randomly generated Get used to nested repetition statements 2.1 Write a C program to print the series of the perfect numbers less than a natural number N input by a user from the keyboard A perfect number is a number equal to the total sum of all of its factors N = 30: 6, 28 2.2 Write a C program to print the series of the first N prime numbers with a natural number N input by a user from the keyboard A prime number is a number that has only two factors: and itself N = 5: 2, 3, 5, 7, 11 2.3 Write a C program to print the following square matrices with a size N input by a user from the keyboard 2.3.1 A square matrix of the even numbers below the non-main diagonal 10 10 10 10 10 8 10 2.3.2 The square matrix of the odd number above the non-main diagonal 9 11 11 11 11 11 11 2.3.3 The square matrix of the even numbers above the main diagonal 10 10 10 10 10 10 2.3.4 The square matrix of the odd numbers below the main diagonal 11 11 11 11 11 11 2.4 Write a C program to find the maximum value and the minimum value and their positions (row, column) in an NxM matrix of numeric values input by a user from the keyboard where N and M are two natural numbers greater than zero also input by a user from the keyboard Start more complex data processing 3.1 Write a C program to approximate a value of the following functions where x is a floatingpoint number in [0, 1] and N is a natural number for controlling an approximation accuracy: n