CSCI 1312 (Introduction to Programming for Engineering):
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.
- Simple example from 9/11 class (revised 9/14):
example-simple.c.
- "Make change" example:
make-change.c.
- Simple example of if/else:
example-conditional.c.
- Programs to solve quadratic equations (real roots only),
multiple versions:
- Simple examples of recursion, mostly from class:
- Simple examples of loops, mostly from class:
- More examples of loops:
- Example of use of arrays:
- "Floating point is strange" examples:
- Example of "Monte Carlo" calculation:
monte-carlo-1.c.
- Example of using command-line arguments:
echo-args.c.
- Examples of simple I/O:
- Example of pointer arithmetic and string function:
pointer-arith.c.
- Example of working with multiple files and character functions
(not from class):
countchars.c.
- Examples of things mentioned only briefly in class:
- Use of dynamic memory allocation (malloc)
to create a 1D array,
and of converting command-line arguments to numbers
(strtol):
array-dynamic.c.
- Various ways of creating a 2D array:
array2d.c.
- Use of struct to create a user-defined type
(for points in 2D space)
struct-example.c.
Other files