CSCI 1320 (Principles of Algorithm Design I):
Sample Programs
Disclaimer: Code linked from this page is intended as a
cleaned-up and commented version of examples from class.
Many programs and classes could be further improved with
regard to functionality or design, but then they would
no longer be as close to what we did in class.
Programs
- "Hello, world" program:
hello.c.
- Program to get two numbers and print their sum and product
(from 9/18 class, renamed):
sum-and-product.c.
- Program to "make change" (from 9/20 class):
make-change.c.
- Revised program to "make change" (from 9/27 class):
make-change-improved.c.
- Program to compute hypotenuse of right triangle (modified version
of program written in 10/02 class):
hypotenuse.c.
- Program to convert inches to centimeters, etc. (completed
version of program written in 10/10 class):
converter.c.
- Program to compute Fibonacci numbers using recursion
(from 10/16 class):
fibonacci.c.
- Program to "count" using recursion (from 10/16 class):
count-with-recursion.c.
- Program to "count" using loops (from 10/16 class):
count-with-loops.c.
- Revised program to convert inches to centimeters, etc.
(from 10/18 class)
better-converter.c.
- Program to add a series of numbers (from 10/23 class):
add-numbers.c.
- Program to print a series of numbers in reverse order using recursion
(from 10/23 class):
reverse-print.c.
- Program to convert decimal to binary, not very nicely
(from 10/23 class):
dec-to-bin.c.
- Program to convert decimal to binary, more nicely, using recursion
(from 10/23 class):
dec-to-bin-r.c.
- Program to read numbers from a file and copy to two output
files (from 10/25 class):
odd-even.c.
- Program to read text from a file and copy to output file,
changing case (from 10/25 class):
change-case.c.
- Program to create an array, put values into it, and sum
them (from 11/01 class):
array-sum.c.
- Program to print input numbers in reverse order and compute
their sum, using an array (from 11/06 class):
add-numbers-array.c.
- Program to compute and print frequency table from input
(from 11/06 class):
frequency.c.
- Program to test selection sort and binary search
(from 11/08 and 11/13 classes)
sort-search.c.
- Program to do some simple things with pointers
(from 11/15 class)
play-with-pointers.c.
- Program to illustrate using pointers as function parameters
(from 11/15 class)
get-two-number.c.
- Revised program to test selection sort (from 11/27 class)
sort-with-count.c
(version using local variable-length array),
sort-with-count-2.c
(version using malloc to get space for array).
- Program showing simple function using string (from 11/27 class)
simple-string-fcn.c
- Improved version of "change case" program, showing getting
file names from the user (from 11/29 class)
change-case-improved.c
- Program to echo command-line arguments (from 11/29 class)
my-echo.c
- Program showing simple example of struct (from 11/29 class)
struct-example.c
Other files
- Sample makefile Makefile
for compiling C programs.
Note:
To obtain a makefile, use your browser's download function;
cutting and pasting will likely turn the tabs in the makefile
into spaces and cause it to not work.
Put the makefile in the directory in which you want to
compile.
All the makefiles linked from this page begin with
brief documentation on their use (the "usage examples").