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 (9/02):
simple-example.c.
- "Count change" program (9/02, 9/07):
count-change.c.
- Quadratic equation program (9/12, 9/14):
quadratic.c.
- Quadratic equation program using function (9/16):
quadratic-as-function.c.
- Simple example of function with pointer parameters (9/19):
simple-function-with-ptrs.c.
- Quadratic equation program using two functions (9/19):
quadratic-as-function-revised.c.
- Program to sum numbers using recursion (9/21):
sum.c.
- Program to compute factorial using recursion (9/21):
fac.c.
- Program to compute element of Fibonacci sequence using recursion,
from 9/21):
fib.c.
- Program to "count up" using recursion (9/21):
count.c.
- Program to "count up" by increment using recursion (9/21):
count-incr.c.
- Program to print a line of text in reverse (example of character
input and recursion) (9/23):
reverse.c.
- Program to get an integer without using scanf (9/23, 9/26):
getint.c
(complete),
getint-improved.c
(slightly neater version, not in class).
- Program to compute factorial using loop (9/28):
fac-loop.c.
- Program to compute element of Fibonacci sequence using loop (9/28):
fib-loop.c.
- Program to sum numbers using loop (9/28):
sum-loop.c.
- Program to print rectangle of x's using nested loops (9/28):
print-rectangle.c.
- Program to average numbers (9/30):
average.c.
- Program to get an integer without using scanf using loops (9/30):
getint-loop.c
- Program to demonstrate numerical integration (10/03, with
modifications):
numerical-int.c.
- Version of program to demonstrate numerical integration that
also illustrates looping until convergence
(10/03, with modifications):
numerical-int-with-convergence.c
- Program to demonstrate Monte Carlo method (10/05):
monte-carlo.c
- Simple examples of file I/O (10/07):
simplefile.c,
simplefile-char.c,
simplefile-fmt.c.
- Program to compute variance (10/17):
variance.c
- Program to count different characters (10/19):
count-chars.c.
- "Floating point is strange" examples (10/19):
float1.c,
float2.c.
- Program illustrating passing arrays to functions (10/21):
sort-example.c.
- Simple "ASCII art" program (10/02, 10/24):
ascii-art.c.
- Example of using both index and pointer to access elements of an
array (10/31):
arrays-versus-pointers.c.
- Example of operating on strings in various ways (11/02):
simple-strings.c.
- Palindrome program (11/02, 11/04):
palindrome.c.
- Program to add command-line arguments (11/04):
addargs.c.
- Program to generate sequence of "random" integers and sort them,
incomplete version (11/04):
sort-test.c.
- Revised sort program using qsort to sort (11/09):
sort-test-qsort.c.
- Revised numerical-integration program showing approximating areas
under two curves (11/09):
numerical-int-revised.c.
- Data type for "US money" and test program (11/11, 11/14):
Makefile,
simple-us-money.h,
simple-us-money.c,
simple-us-money-test.c.
- Program to compute Julian date (11/16):
jdate.c.
- Program to count elements in "ranges" (11/16):
ranges.c.
- Program to show long in bit form, two ways (11/18):
showlong.c.
- Program to demo bit operations (11/18, 11/21):
flags.c.
- Programs to write, read binary file (11/21):
writebin.c,
readbin.c.
- Implementation of sorted linked list of integers and test program
(11/28, 11/30):
sorted-int-list.h (type definition and function declarations)
sorted-int-list-recur.c (function definitions, recursive version),
sorted-int-list-iter.c (function definitions, iterative version),
simple-test.c
(very simple test program using only the type definition),
test-sorted-int-list.c (more elaborate test program -- no real need to read closely),
Makefile
(makefile to compile the elaborate test program, once each for
recursive and iterative versions).
Other files