0% found this document useful (0 votes)
125 views6 pages

Computer Programming - C - : Mid-Term Exam For 02

This document provides the instructions and problems for a C mid-term exam. It outlines 6 programming problems that students must complete, including calculating electric bills, matrix operations, recursive functions, finding maximum/minimum values, and determining the cheapest travel route between points. Students are instructed on file naming conventions and how files will be collected.

Uploaded by

張帕姆
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views6 pages

Computer Programming - C - : Mid-Term Exam For 02

This document provides the instructions and problems for a C mid-term exam. It outlines 6 programming problems that students must complete, including calculating electric bills, matrix operations, recursive functions, finding maximum/minimum values, and determining the cheapest travel route between points. Students are instructed on file naming conventions and how files will be collected.

Uploaded by

張帕姆
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Computer Programming - C Mid-Term Exam for 02

Lee 2005/11/22

Notice 1. Plagiarism, the use of USB flash drive and discussion are prohibited. 2. Students only can take pen and textbook in the classroom. 3. In the programming examination, there are five problems, and the naming of your program is defined in the following format. If your student ID is b94902001, your programs name for problem 1 is B94902001_P1.c, and B94902001_P2.c for problem 2. If you want to resubmit your program, please name it by version, like 4. B94902001_P1_ver1.c for problem 1 version 1. TAs will use USB flash drive to collect your programs in our program spool.

pp. 1

Problem 1 Comments for Course and Exam (10 points)


Description Please write down your comments for course and exam.

Problem 2 - Electric Bill Calculation (20 points)


Description In Taiwan, Taiwan Power Company adopts the following accumulated formula to calculate an electric bill for home-use. In this formula, they also separate summer use and non-summer use. Level Summer use (6/1~9/30) ~ 110 111 ~ 330 331 ~ 500 501 ~ 2.1 2.7 3.3 2.7 3.4 Non-summer use (days exclude 6/1~9/30) 2.1 2.4

For example, if your family use 330 degree a month, the cost of summer use is 110 * 2.1+ (330 - 110) * 2.7 = 825 And the corresponding cost of non-summer use is 110 * 2.1+ (330 - 110) * 2.4 = 759 You are asked to show the bills in both summer use and non-summer use. Sample Input Please input the degree of electric consumption: 330 Sample Output 330 degree: 825 (summer use), 759 (non-summer use)

pp. 2

Problem 3 - Matrix Algebra (20 points)


Description Given a square matrix A (m*m, 2m10), we have the following functions to calculate matrix transpose division
aji. 1 (function matrixD). A

two

(function matrixT) and matrix

AT is defined by exchanging all elements aij with Now, you are asked to

1 1 is defined by replacing all elements aij with . aij A

implement these two functions and write your main program by calling these two 1 functions to compute T . A Sample Input 1 Please input the size of a square matrix: 5 Please input values for a square matrix:

1 3 1 1 4

0 1 3 1 1

2 1 1 2 2

3 2 1 3 1

4 1 1 1 3
1 : AT

The matrix of

undefined
Sample Input 2 Please input the size of a square matrix: 5 Please input values for a square matrix:

1 3 1 1 4

1 1 3 1 1

2 1 1 2 2

3 2 1 3 1

4 1 1 1 3

Sample Output2 The matrix of 1 : AT

1.00 1.00

0.33 1.00

1.00 0.33

1.00 1.00

0.25 1.00
pp. 3

0.50 0.33 0.25

1.00 0.50 1.00

1.00 1.00 1.00

0.50 0.33 1.00

0.50 1.00 0.33

Problem 4 - Calling of Recursive Call (20 points)


Description The diagram shown below is spiral of equilateral triangles with side lengths which follow the Padovan sequence. The Padovan sequence is the sequence of Now, we define another series of A(n). 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.

A(n) is the times of calling P(0) when calculating P(n) recursively. Please print the recursive form of A(n) and then calculate it, given n (0 n 20 . 20)

Sample Input Please input a non-negative number: 5 Sample Output The recursive form of A series is ??? A(5) = ???

pp. 4

Problem 5 - Find the Maximum (20 points)


Description Given a sequence of integers, we can find the maximum in the sequence by using our algorithm. The algorithm recursively separates an array into two parts: left and right, finds the maximums of two parts, and then compares and returns the larger one. You are asked to input an integer N (2 N 100) and N integers in sequence. Please write a recursive program to implement this algorithm to find the maximum in the sequence. Sample Input Please input the number in the integer sequence: 5 Please input 5 integers: 20 Sample Output The maximum in 20

60

15

78

30

60 15

78

30 is 78

pp. 5

Problem 6 - Find the Cheapest Tour (20 points)


Description The CSIE travel agent has a lot of tour packages. they want to find the cheapest tour. cost between any two travel points. Given the travel points(TP), Here, we have the cost matrix store the travel The cost is zero means no connection between Please input the start point and

the two travel points and more than zero if these two travel points are adjacent. Now, the CSIE travel agent provides 7 travel points. the end point, and then find the corresponding cheapest tour.

Cost Matrix
TP1 TP1 TP2 TP3 TP4 TP5 TP6 TP7 TP2 TP3 TP4 TP5 TP6 TP7

0 1000 2000 0 8000 0 2000

1000 0 0 4000 4000 0 0

2000 0 0 0 0 1000 0

0 4000 0 0 1000 1000 0

8000 4000 0 1000 0 0 0

0 0 1000 1000 0 0 0

2000 0 0 0 0 0 0

Sample Input Please input elements of corresponding cost matrix:

0 1000 2000 0 8000 0 2000

1000 0 0 4000 4000 0 0

2000 0 0 0 0 1000 0

0 4000 0 0 1000 1000 0

8000 4000 0 1000 0 0 0

0 0 1000 1000 0 0 0

2000 0 0 0 0 0 0

Please input the start point: 1 Please input the end point: 4 Sample Output The cheapest tour from 1 to 4: 1 -> 3-> 6 -> 4 The cost : 4000

pp. 6

You might also like