Midterm Exam

Midterm Exam - Midterm Exam Instructions These questions...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Midterm Exam Instructions These questions are an example of what you will expect in the CS240 midterm exam. Write by hand neatly the solutions and turn them in during the midterm exam on Monday. The solutions to the questions will be posted on Sunday before the exam. We recommend you not to see the solutions until you have tried to solve the programs on your own. The goal of this review is for you to practice for the exam. Your solutions will be graded as "turned in" or "not turned in". We may surprise you and include one of these questions in the midterm exam. 1. A Fibonacci number is defined as follows: f 0 =0 f 1 = 1 f k = f k-1 + f k-2 That means each Fibonacci number is the sum of the previous two. Write a function fib that computes the nth Fibonacci number. int fib(int k) { } int main() { int n; scanf(%d, &n); printf(The %dth Fibonacci number is %d\n, n, fib(n)); } 2. Write a program tohex arg1 that will convert the argument in decimal arg1 to hexadecimal and print it in the form 0xHHHH. If arg1 is missing or it is not a decimal number, the program will print an error.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3. Write a program
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Midterm Exam - Midterm Exam Instructions These questions...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online