Programming, Problem Solving, and Abstraction with C

by

Alistair Moffat


C Programs from the Book (Revised edition, 2012)


Warranty: These programs are supplied for educational purposes only. There is no absolutely no warranty of any kind that they are fit for any purpose whatsoever, and no permission or consent is granted for you to use them in any way that might put you at risk of financial or personal loss, real or implied. (Sorry to be so negative, that one is for any lawyers that happen to be looking.)

Permission: You may copy these programs onto any computer that you are using as part of your education. You may also reproduce them into any work of your own, including making them available on your personal or institutional web site, provided always that you continue to acknowledge my authorship of them by retaining unchanged the comment that appears at the end of each file, and provided that you reproduce both the "Warranty" and "Permission" statements that appear in this file in any electronic listing of them.


Chapter 1
	page   6	helloworld.c
	page   8	addnumbers.c

Chapter 2
	page  16	overflow.c
	page  17	rounding.c
	page  17	addorder.c
	page  24	format.c
	page  25	mixedvals.c
	page  26	spherevol.c
	

Chapter 3
	page  35	equalinif.c
	page  35	danglingelse.c
	page  36	threetest.c
	page  37	taxation.c
	page  39	switch1.c
	page  40	switch2.c
	

Chapter 4
	page  46	forloop1.c
	page  47	daynumber.c
	page  48	forloop2.c
	page  48	forloop3.c
	page  51	savings.c
	page  52	daynumber-squash.c
	page  52	daynumber-braces.c
	page  54	threen.c
	page  55	isprime.c
	page  57	readloop1.c
	page  58	fortcomm.c
	

Chapter 5
	page  64	savingsfunc.c
	page  67	savingsfunc.c
	page  68	isprimefunc.c
	page  70	usemathlib.c
	page  73	savingsfuncgen.c
	page  74	triangle.c
	page  77	croot.c
	page  78	croot.c
	

Chapter 6
	page  85	void.c
	page  86	scope1.c
	page  87	scope2.c
	page  89	scope3.c
	page  92	pointer1.c
	page  94	pointer2.c
	page  95	pointer3.c
	page  96	readnum.c
	

Chapter 7
	page 100	array1.c
	page 102	insertionsort.c
	page 104	insertionsort.c
	page 107	insertionsort.c
	page 108	matrixadd.c
	page 110	twodarray.c
	page 111	matrixadd.c
	page 115	pointer4.c
	page 118	string1.c
	page 120	strcpy.c
	page 121	getword.c
	page 122	words.c
	page 125	progargs.c

Chapter 8
	page 129	struct.c
	page 130	struct.c
	page 133	nested.c
	page 136	struct.c

Chapter 9
	page 142	isprimefunc.c
	page 144	hanoi.c
	page 145	subsetsum.c
	page 148	gamble1.c
	page 148	gamble2.c
	page 149	random.c
	page 151	montecarlo.c
	page 153	linelength.c
	page 155	bisection.c
	page 158	spring.c

Chapter 10
	page 165	sizeof.c
	page 166	malloc.c
	page 168	realloc.c
	page 171	listops.c
	page 172	listops.c
	page 173	listops.c
	page 175	listeg.c
	page 179	funcpoint.c
	page 180	funcarg.c
	page 181	funcarg.c
	page 182	callqsort.c
	page 184	treeops.h
	page 184	treeops.c
	page 185	treeops.c
	page 186	treeops.c
	page 187	treeeg.c
	page 188	treeeg.c

Chapter 11
	page 196	twolines.c
	page 198	fread.c
	page 201	mergefiles.c

Chapter 12
	page 206	binarysearch.c
	page 209	hashing.c
	page 210	hashing.c
	page 210	hashscaffold.c
	page 211	hashingbad.c
	page 213	quicksort.c
	page 213	sortscaffold.c
	page 214	quicksort.c
	page 216	quicksort.c
	page 219	mergesort.c
	page 222	heapsort.c

Chapter 13
	page 233	intbits.c
	page 237	preproc.c

Alistair Moffat
Department of Computing and Information Systems
The University of Melbourne, Australia
ammoffat / unimelb.edu.au
January 29, 2003, February 28, 2012, March 2, 2013

Mandatory disclaimer: This page, its content and style, are the responsibility of the author and do not necessarily represent the views, policies, or opinions of The University of Melbourne.