A Sample Program

Listing 5.16 is a useful program (if you're a runner or know one) that illustrates several of the ideas in this chapter. It looks long, but all the calculations are done in six lines near the end. The bulk of the program relays information between the computer and the user. We've tried using enough comments to make it nearly self-explanatory. Read through it, and when you are done, we'll clear up a few points.

Listing 5.16. The running.c Program
 // running.c -- A useful program for runners #include <stdio.h> const int S_PER_M = 60; // seconds in a minute const int S_PER_H = 3600; // seconds in an hour const int M_PER_K = 0.62137; // miles in a kilometer int main(void) { double distk, distm; // distance run in km and in miles ...

Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.