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 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.
- Programs to get two numbers and print their sum
(from 9/16 class):
add-two-ints.c,
add-two-floats.c.
- Program to "make change" (from 9/18 class, two versions):
make-change-1.c,
make-change-2.c.
- Program to find solutions of quadratic equation (from 9/25 class,
completed/corrected):
quadratic-equation.c.
- Program to compute hypotenuse of right triangle (from 10/09 class):
hypotenuse.c.
- Program to convert inches to centimeters, etc. (completed
version of program written in 10/09 and 10/16 classes):
converter.c.
- Program to compute factorials using recursion
(from 10/16 class):
factorial.c.
- Program to "count" using recursion (from 10/28 class):
count-with-recursion.c.
- Program to "count" using loops (from 10/28 class):
count-with-loops.c.
- Program to compute factorials using loops (from 10/28 class):
factorial-with-loops.c.
- Revised program to convert inches to centimeters, etc.
(from 10/30 class):
converter-with-repeats.c.
- Program to add a series of numbers (from 11/04 class):
add-numbers.c.
- Program to print a series of numbers in reverse order using recursion
(from 11/04 class):
reverse-print.c.
- Program to convert decimal to binary, not very nicely
(from 11/04 class):
dec-to-bin.c.
- Program to convert decimal to binary, more nicely, using recursion
(from 11/04 class):
dec-to-bin-r.c.
- Program to read numbers from a file and copy to two output
files (from 11/11 class):
odd-even.c.
- Program to read text from a file and copy to output file,
changing case (from 11/11 class):
change-case.c.
Another way (using functions that read and write single
character):
change-case-another-way.c.
- Program to read numbers and compute
their sum, using an array (from 11/13 class):
add-numbers-array.c.
- Program to read grades and print how many fall into various
ranges (from 11/13 class, completed version):
grades-frequency.c.
- Program showing use of pointers to "return" two values from
a function (from 11/25 class):
divide.c.
- Program showing simple function using string (from 12/02 class)
simple-string-fcn.c
- Improved version of "change case" program, showing getting
file names from the user (from 12/02 class)
change-case-improved.c
- Program to echo command-line arguments (from 12/02 class)
my-echo.c
- Program to generate N numbers and sort them (from 12/04 class,
corrected and improved)
sort-demo.c
- Program showing simple example of struct (mentioned in 12/04
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").