Planning a Program
Now that you've seen the mechanics of writing array functions, let's try a more programming-oriented example. Our self-appointed task is to write a program that reads numbers into an array, prints the entered numbers, and reports the average. To make the program more realistic, require that it allow the user to terminate input, if desired, before the array is filled. This will enable the program to process any number of items up to a maximum determined by the array size. Also, you want to avoid calculating the average if no numbers are entered.
General Plan
Conceptually, the program should perform three major tasks: reading in a set of numbers, printing the set of numbers, and calculating the average. Now that you know how ...
Get C Primer Plus®, Third 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.