August 1997
CA208: 'C' PROGRAMMING

QUESTION 5

Total Marks: 20 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 5

5. (a) Write a self-contained C program that prints the square of the integers 0 through 9:
(i) using a for statement [3]
(ii) while statement [3]
(b) Given the following definition of a linear linked-list type as the representation of the elements in a stack,

(i) Write a procedure push, that has the procedure prototype shown below, that pushes the the element x onto the stack stack. [4]
void push(StackType *stack, int x);
(ii) Write a function sizeStack, that has the function prototype shown below, that returns the number of elements in the stack stack. [4]
int sizeStack(StackType stack);
(iii) Write a function pop, that has the function prototype shown below, that returns and then removes the top element from the stack stack. You should call the function error (with prototype below), if it is not possible to remove an element from the stack. [6]
int pop(StackType *stack);
void error(void);