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
k1
+ f
k2
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.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document3. Write a program
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 REGO
 Decimal, ASCII, Fibonacci number

Click to edit the document details