0% found this document useful (0 votes)
31 views4 pages

COMP20005 Numerical Computation Test 2025

The document is a sample mid-semester test for the course COMP20005, focusing on numerical computation in C, with a total of 10 marks. It includes instructions for students regarding test conditions, prohibited materials, and specific questions related to the Fibonacci sequence and output formatting. Students are required to write functions in C and adhere to strict guidelines during the test.

Uploaded by

lyu chloe
Copyright
© All Rights Reserved
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)
31 views4 pages

COMP20005 Numerical Computation Test 2025

The document is a sample mid-semester test for the course COMP20005, focusing on numerical computation in C, with a total of 10 marks. It includes instructions for students regarding test conditions, prohibited materials, and specific questions related to the Fibonacci sequence and output formatting. Students are required to write functions in C and adhere to strict guidelines during the test.

Uploaded by

lyu chloe
Copyright
© All Rights Reserved
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

School of Computing and Information Systems

COMP20005 Intro. to Numerical Computation in C

Mid-Semester Test Sample, Semester 2, 2025

Reading Time: 5 minutes.

Writing Time: 30 minutes.

Authorised Materials: None.

Number of pages: 6.

Instructions to Students: This paper contains 10 marks.

Be sure to write your student number clearly on the answer sheet.

This assessment is closed book, and you may not make use of any printed, written, electronic, or
online resources.

All questions should be answered in the spaces provided on the separate answer sheet.

You must remain in the test venue until the end of the test, and may not leave early.

You must not communicate with any other student in any way from the moment you enter the test
venue until after you have left the test venue. All phones and other network, communication, and
electronic devices must be switched completely off while you are in the test room.

Calculators and dictionaries are not permitted.

You are not required to write comments except when you are explicitly asked to. If a question says
“write a function”, you may write further relevant functions if you believe that a decomposition of
the problem is appropriate.

You may make use of library functions except when their use is explicitly prohibited. If you do
make use of library functions, you must add suitable #include lines at the start of each corre-
sponding answer.

Constants should be #define’d prior to use, when appropriate.

You may use the back of this page to prepare a draft of any answer, but you must copy your answer
onto the answer sheet before the end of the test.

Only work that is on the answer sheet will be marked.


Student Number:

Question 1 (4 marks)
The Fibonacci sequence is a famous series of numbers whereby the i-th number, Fi , is equal to
Fi−1 + Fi−2 : 0, 1, 1, 2, 3, 5, 8, 13, 21, etc. Notice that the sequence is “seeded” with the values 0 and
1, or more precisely, F0 = 0 and F1 = 1. You should assume this definition going forward.
Write a function
double average_fib(int k)
that calculates and returns the average of all Fibonacci numbers less than or equal to k. For example:
(1) Given k = 3, there are five Fibonaci numbers ≤ 3, namely 0, 1, 1, 2, 3, and the average of these
is 1.4. (2) Given k = 15, there are eight Fibonacci numbers ≤ 15, namely 0, 1, 1, 2, 3, 5, 8, 13, and
the average of these is 4.125.
Your solution should generalise for all k ≥ 0, but you do not need to consider integer overflow.
Furthermore, input validation is not necessary to correctly answer this question, i.e., your function
doesn’t have to handle negative k values.
Question 2 (6 marks)
Write a main function that reads an integer n and prints n output lines of characters following the
pattern shown below (“mac:” is the command prompt).
mac: ./program
Enter number of output lines: 4
Invalid input.
mac: ./program
Enter number of output lines: 1
###
mac: ./program
Enter number of output lines: 5
#----#----#
#----#----#
#----#----#
#----#----#
#----#----#
Your program should check if n is a positive odd integer. If not, print an error message and exit.

You might also like