The test is open-everything with the sole limitation that you
neither solicit nor give help while the exam is in progress.
Submit all answers on these exam sheets. No extra sheets are
allowed. You have only thirty minutes to complete the exam.
I don't suspect many people will finish all
the problems; the intent is to make sure the people most
familiar with the material get the best grades.
| Problem | You got | Out of |
1 | | 20 |
2 | | 20 |
3 | | 20 |
4 | | 20 |
5 | | 20 |
TOTAL | | 100 |
- Write a C function that takes in
two strings and the returns the string with the characters of each
interleaved, as in the following examples:
- interleave("dog", "rat") == "droagt"
- interleave("capybara", "it") == "ciatpybara"
- interleave("java", "suckzzz") == "jsauvcazzz"
- Write a C function
(call it dot_product) that takes in two arrays of doubles,
and returns the sum
of the products of corresponding items. Note that because
this is C, your function will need to take in a third parameter,
namely the size of the arrays. Example: if a were
the array [5.0, 3.0, 1.0], and b were the array
[6.0, -3.0, 2.0], then dot_product(a, b, 3) = 23.0.
- Write a complete C program that writes, to standard output,
its longest commandline argument. If there are multiple
longest arguments, just write one of them.
- Write a C function, from scratch
(that means no library functions),
that returns a substring of a string, given the first index
(inclusive) and the last index (exclusive). One other
rule: do not access individual characters of the string
via array indexing; in other words you can't write expressions
like s[i]. Instead, make use of the fact that a string
is really a pointer to its first element, and adding one to
a character pointer makes it point to the next character
in the string. Examples:
substring("snoopdog", 2, 6) ==> "oopd"
substring("snoopdog", 32, 456) ==> ""
substring("snoopdog", -5, 2) ==> "sn"
- Write a C function that takes in a string s and an integer k, and
returns a new string containing every kth character in s. For
example:
f("Go to the beach", 3) ==> "Gtt a"
f("Whatever", 2) ==> "Waee"
f("This function is really weird", 5) ==> "Tfisle"