Tải bản đầy đủ (.pdf) (2 trang)

Lab 7 recursive functions

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (202.44 KB, 2 trang )

Course: Programming Fundamentals (C language)
LAB 7 – Recursive Functions
Main content:
1.
2.
3.
4.

Get used to recursion
Get used to recursive function definitions and function calls
Start more complex data processing
Check coding styles

Practice:
1. Get used to recursion
1.1. Write the base cases and recursive cases of each recursive function used for the following
problems using pseudo codes in their corresponding programs:
1.1.1.
1.1.2.
1.1.3.
1.1.4.

Print all the Fibonacci numbers that are less than a given natural number
Print all the perfect numbers that are less than a given natural number
Print all the prime numbers that are less than a given natural number
Print all the symmetric integer numbers from N integer numbers randomly
generated from -1000000 to 1000000. Examples of a symmetric integer number are
given as: -219989912; -5; 1; 202; 145541; 2389832; …

2. Get used to recursive function definitions and function calls
2.1. Write a C program using recursive functions to get a natural number, N > 0, input by a user


from the keyboard.
2.2. Write a C program using recursive functions to find the greatest common divisor of two
natural numbers.
2.3. Write a C program using recursive functions to check if an integer number has a sum of all
the even digits equal to another sum of all the odd digits.
2.4. Write a C program using recursive functions for each aforementioned problem. Please
populate data for the inputs of each program by yourselves for illustration if needed.
3. Start more complex data processing
3.1. Write a C program using recursive functions to print all the positions of the smallest digit in
an integer number input by a user from the keyboard. It is supposed that the most left digit
is counted at position 0 from the left to the right. How many positions are there?
3.2. Write a C program using recursive functions to approximate a value of the following
functions where x is a floating-point number in [0, 1] and N is a natural number for
controlling an approximation accuracy: n<=N.
3.2.1. Function ln(1+x)

1


3.2.2. Function tan-1x

3.3. Write a C program using recursive functions to generate and print an inversed 9-based
complementary number of an integer number input by a user from the keyboard.
Input 1: An integer number = 90145
Output 1: Its inversed 9-based complementary number = 45890
Input 2: An integer number = -213098
Output 2: Its inversed 9-based complementary number = -109687
4. Check coding styles
For each C program that you have written, check coding styles with the following points:
- How have you used blank lines?

- How have you used tabs for alignment?
- How have you used comments in your source code files?
- Above all, how about your naming conventions? What have you named in your source code
files?

2



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×