• 沒有找到結果。

Introduction to Computer Programming, 2005

N/A
N/A
Protected

Academic year: 2022

Share "Introduction to Computer Programming, 2005"

Copied!
2
0
0

加載中.... (立即查看全文)

全文

(1)

Introduction to Computer Programming, 2005

Program Assignment Ⅴ

2005/11/1

Scope: Chapter 2 to chapter 5 in Textbook (Recursion) Notice:

1. Plagiarism is prohibited.

2. TA will randomly choose 10 students to demonstrate program.

3. Please make your code readable. Reference for coding style:

http://www.cs.usyd.edu.au/~scilect/tpop/handouts/Style.htm

Problem: Your mission is to practice an iteration and recursion version of Padovan sequence. The Padovan sequence is the sequence of integers P(n) defined by the initial values P(0) = P(1) = P(2) = 1, and recurrence relation P(n) = P(n-2) + P(n-3) where n > 2. We also define Q(n) and R(n). Q(n) is defined by the area of equilateral triangle with side length P(n). R(n) is defined by the initial values R(0)

= Q(0) and the recurrence relation R(n) = Q(n) + R(n - 1) where n > 1.

The above diagram is spiral of equilateral triangles with side lengths which follow the Padovan sequence. (from http://en.wikipedia.org/wiki/Padovan_sequence)

Hint: Using array implementation to store data you calculated in iteration version of Padovan sequence.

Deadline: 2005/11/15, 12:00 pm Description:

1. In your program, you must have two functions; one is iteration version and another is recursion version.

2. In order to test your program, user can give the value of n to list Padovan sequence from P(0) to P(n) and corresponding accumulated triangle area.

3. In this assignment, we only accept non-negative integer number n (0 ≦ n ≦ 1000) as input value.

4. The area of equilateral triangles with side length n is 2 4

3n , and you are asked to use math library to

calculate the area of equilateral triangles with side length of n.

(2)

Example Output:

Please choose computing version (1 for iteration computing, 2 for recursion computing): 1 By iteration,

Please input the value of n for Padovan sequence: 3 P(n): 1, 1, 1, 2

Q(n): 0.433, 0.433, 0.433, 1.732 R(n): 0.433, 0.866, 1.299, 3.031 Bye.

Please choose computing version (1 for iteration computing, 2 for recursion computing): 2 By recursion,

Please input the value of n for Padovan sequence: 3 P(n): 1, 1, 1, 2

Q(n): 0.433, 0.433, 0.433, 1.732 R(n): 0.433, 0.866, 1.299, 3.031 Bye.

Hand-in:

1. Pack your program (HW5_STUDENTID.c) and document (HW5_STUDENTID.doc (or pdf)) into a compressed file (HW5_STUDENTID.rar (or zip))

2. In the document, you can explain how to achieve this program and use simple flow chart to show your program architecture. Also, you can show what kind of problems you met on developing this program and how to solve them. Notice, use one page to document your program. You must use flow chart to illustrate this homework assignment.

3. Send the compressed file to [email protected] with mail subject [cprog2005]HW5_STUDENTID

4. For example, if your student id is b94902200, the program file name is HW5_b94902200.c, the document file name is HW5_b94902200.doc and compressed file name is HW5_b94902200.rar.

參考文獻

相關文件

[r]

2002, Kanpur, India, Agrawal, and university students Kayal and Saxena found a polynomial time algorithm for the primality testing problem, thereby proves it is a problem in class

My research mainly in discussing the use of a small equilateral triangle covering large equilateral triangle, and the minimum value of the small equilateral triangle side

First Note that f (x) is an even function, hence symmetric with respect to the y-axis.. Therefore the two vertices of the rect- angle we are considering are f (x) and f (−x) for

[r]

With the help of the pictures and the words below, write a journal entry about what happened.. Write at least

Reading Task 6: Genre Structure and Language Features. • Now let’s look at how language features (e.g. sentence patterns) are connected to the structure

 Promote project learning, mathematical modeling, and problem-based learning to strengthen the ability to integrate and apply knowledge and skills, and make. calculated