August 2000 QUESTION 5 Total Marks: 15 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
(a) Give an example of a program control
flow statement in C. [1 mark] (b) Explain what is meant by the base
case of a recursive test, and explain why it is necessary for a recursive
test to have a base case. [2 marks] (c) Explain the difference between stack
and heap allocated data in C. [2 marks] (d) The following function is intended
to swap the integers a and b. Identify the problem with this function,
and show how this could be remedied. (e) Write a function that prompts the
user to enter a number in the range 0 - 5. If the number is not in
that range, the prompt should be repeated, else the function should
return the number input. [4 marks] (f) Implement the recursive procedure
Remainder, such that it takes three parameters, a number, a divisor
and a remainder. The function should recursively subtract the divisor
from the number until only the remainder remains; and return the remainder
to the caller. [4 marks] |