Chapter 4 - Functions and Program Structure
If you are intending to attempt solutions 4-3 through 4-10, you will find testing
your solution to be a somewhat less laborious task if you download the following code:
Kernighan and Ritchie's Polish calculator source
It was when he was typing up this lot that the problem of copyright first occurred to
Richard Heathfield - after all, it's quite a substantial quote from the book. Fortunately for Richard,
Dennis Ritchie had no objections (but he did check to make sure there wouldn't be
any other verbatim quotes of comparable size!).
| Ex No | Pg No | Exercise | Solution | Solved by |
|---|---|---|---|---|
| 1 | 71 |
Write the function |
Listing krx401 | Rick Dearman Pilcrow |
| 2 | 73 |
Extend |
Listing krx402 | Dann Corbit |
| 3 | 79 |
Given the basic framework, it's straightforward to extend the
calculator. Add the modulus ( |
Listing krx403 | Bob Wightman |
| 4 | 79 |
Add commands to print the top element of the stack without popping, to duplicate it, and to swap the top two elements. Add a command to clear the stack. |
Listing krx404 | Bob Wightman |
| 5 | 79 |
Add access to library functions like |
Listing krx405 | Bob Wightman |
| 6 | 79 |
Add commands for handling variables. (It's easy to provide twenty-six variables with single-letter names.) Add a variable for the most recently printed value. |
Listing krx406 | Cat 1 Solution by Bob Wightman Jesus Alvarez |
| 7 | 79 |
Write a routine |
Listing krx407 | Steven Huang |
| 8 | 79 |
Suppose that there will never be more than one character
of pushback. Modify |
Listing krx408 | Steven Huang Jesus Alvarez |
| 9 | 79 |
Our |
Listing krx409 | Franz Fritsche Jesus Alvarez |
| 10 | 79 |
An alternate organization uses |
Listing krx410 | Franz Fritsche |
| 11 | 83 |
Modify |
Listing krx411 | Gregory Pietsch |
| 12 | 88 |
Adapt the ideas of |
Listing krx412 | Gregory Pietsch Jesus Alvarez |
| 13 | 88 |
Write a recursive version of the function |
Listing krx413 | Gregory Pietsch Jesus Alvarez |
| 14 | 91 |
Define a macro |
Listing krx414 | Gregory Pietsch, Lars Wirzenius |









