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 (8/29):
hello.c.
- Simple example of variables, expressions, input/output (8/31):
simple-example.c.
- "Count change" program (8/31, 9/05, 9/07):
change.c,
change-revised.c,
change-revised-errchk.c.
- Program to find real roots of quadratic equation (9/10, 9/12):
quadratic-solver.c.
- Simple example of function (9/14):
simple-fcn.c.
- Program to find real roots of quadratic equation,
function version (9/14):
quadratic-solver-fcn.c.
- Program to find real roots of quadratic equation,
second function version with pointer arguments (9/17):
quadratic-solver-fcn-revised.c.
- Program to compute factorial using recursion (9/19):
factorial.c.
- Program to compute element of Fibonacci sequence using recursion (9/19):
fibonacci.c.
- Program to sum numbers using recursion (9/19):
sum.c.
- Program to "count down" using recursion (9/21):
countdown.c.
- Program to reverse line of text using recursion (9/21):
reverse.c.
- Program to compute factorial using recursion, with overflow check (9/24):
factorial-with-overflow-check.c.
- Program to sum numbers using loop (9/26):
loop-sum.c.
- Program to compute factorial using loop (9/26):
loop-factorial.c.
- Program to compute element of Fibonacci sequence using loop (9/26):
loop-fibonacci.c.
- Program to get average of numbers (9/28):
average.c.
- Program to print rectangle of x's using nested loops (9/28):
print-block.c.
- Program to get an integer from stdin without scanf, checking for
overflow (9/28):
get-int.c.
- Programs to estimate pi using numerical integration (10/03):
estimate-pi.c,
estimate-pi-with-repeat-1.c,
estimate-pi-with-repeat-2.c.
- Programs to estimate pi using Monte Carlo approach (10/05):
estimate-pi-monte-carlo.c.
- Program to find highest power of two for input (10/08):
power-of-2.c.
- Program to convert lowercase to uppercase (10/08):
shout.c.
- Program to copy file
(simple example of using fgetc, fputc) (10/15):
simplefile-char.c.
- Program to compute sum of numbers from file
(simple example of using fscanf, fprintf) (10/15):
simplefile-fmt.c.
- "Floating point is strange" examples (10/17):
strange-float-1.c,
strange-float-2.c.
- Program to expand tabs (not in class):
expand-tabs.c.
- Program to compute variance (10/22):
variance.c.
- Program to illustrate writing outside array bounds (10/22):
simple-array.c.
- Program to count characters (10/24):
countchars.c.
- Simple ASCII-art program (example of using 2D array) (10/29):
ascii-art.c.
- Bubble sort of "random" data (10/31):
bubble-sort-vla.c
(with variable-length array),
bubble-sort-malloc.c
(with dynamically allocated array).
- Program to get and echo line of text using fgets() (11/02):
echoline-fgets.c.
- Program to find length of text string, several ways (11/02):
simple-strings.c.
- Program to reverse line of text using array, several ways (11/05):
reverse-using-array.c.
- Program to echo command-line arguments (11/05):
echo-args.c.
- Program building 2D array two ways (11/07):
2d-array.c.
- Program to define and test a type for 3D vectors (11/14):
3d-vectors.h,
test-3d-vectors.c.
- Program to find difference in days between two dates
(example of using struct (11/19):
date-difference.c.
- Makefile example (11/26):
Source code files and Makefiles
here,
or ZIP archive
here.
- Sorted linked list (11/28):
Source code files and Makefile
here,
or ZIP archive
here.
- Revision of program to sort integers, this time
using qsort (11/30):
use-qsort.c.
- Program to do numerical integration of more than one function
(11/30):
numint.c.
Other files