The exam hall is quiet. Page four of the booklet says, Write a C program to..., ten marks, and your watch says you can spend twenty minutes on it. You know C well enough. And yet this is where many candidates lose marks, and rarely because they don't know the language. They lose them because the program answers correctly for 14 and wrongly for -7. Or because it reads a decimal wage into an int. Or because the question drew an output layout and the program printed something else. Or because there is no sample run, so the marker cannot tell whether the program works without compiling it in his head.
The last chapter stepped back to look at the whole family of languages, how they are grouped and where they came from. Now we sit down at the exam desk again, with a pen and C. This chapter is about the answer itself: how to lay it out, and how to write the programs the papers keep asking for.
By the end you'll be able to build an answer in the order a marker expects: the plan in one line, the program that reads, calculates and prints, then a sample run you worked out by hand. You'll write the programs for decisions (even or odd, income-tax slabs, marks to grade), for menus and loops (the average of the passing marks, a menu-driven calculator), for arrays (maximum, second largest, test code for a sort, common elements, deleting duplicates) and for matrices (row and column sums, diagonals, addition, transpose, multiplication, a triangle in a jagged array). For each one you'll know the trap that costs marks, and you'll have seen the real output.
We go in five parts: how an answer is built, with the first two programs; programs that decide, with switch and goto; loops at work; arrays; and matrices. The loops themselves were taught in the loops chapter; here we use them the way an examiner wants them used.