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 of variables, expressions, input/output (9/01):
simple-example.c.
- "Count change" program (9/06):
change.c.
- Simple example of conditional execution (9/11):
simple-conditional.c.
- Program to find real roots of quadratic equation (9/13):
roots.c.
- Simple example of function (9/15):
simple-fcn.c.
- Program to find real roots of quadratic equation,
first function version (9/15):
roots-fcn.c.
- Simple example of function with pointer parameters (9/18):
divide.c.
- Program to find real roots of quadratic equation,
second function version (9/18, 9/20, still not quite complete):
roots-fcn2.c.
- Program to compute factorial using recursion (9/20):
factorial.c.
- Program to compute element of Fibonacci sequence using recursion (9/20):
fibonacci.c.
- Program to sum numbers using recursion (9/20):
sum.c.
- Program to "count down" using recursion (9/22):
countdown.c.
- Program to echo line of text using recursion (9/22):
echoline.c.
- Program to get an integer from stdin without scanf, using
recursion (9/22):
getint.c.
- Program to get an integer from stdin without scanf, using
recursion, revised version (9/25):
getint-revised.c.
- Program to compute factorial using loop (9/27):
factorial-loop.c.
- Program to compute element of Fibonacci sequence using loop (9/27):
fibonacci-loop.c.
- Program to sum numbers using loop (9/27):
sum-loop.c.
- Program to print rectangle of X's using nested loops (9/27):
silly-nested.c.
- Program to find highest power of 2 not more than input number (9/27):
power-of-2.c.
- Program to get average of numbers (9/29):
average.c.
- Program to get an integer from stdin without scanf,
using a loop (9/29):
getint-loop.c.
- Program to estimate pi using numerical integration (10/02, 10/04):
pi-numint.c.
- Program to estimate pi using numerical integration,
repeating until "convergence" (10/02, 10/04):
pi-numint-repeat.c.
- Silly program to show use of srand() and rand() (10/04):
rands.c.
- Program to compute pi with numerical integration (10/04, 10/06):
pi-monte-carlo.c.
- Program to echo text (10/06):
echo.c.
- Program to echo text between files (10/06):
echo-file.c.
- Program to "count up" using recursion (10/09):
countup.c.
- Program to copy file
(simple example of using fgetc, fputc) (10/13):
simplefile-char.c.
- Program to compute sum of numbers from file
(simple example of using fscanf, fprintf) (10/13):
simplefile-fmt.c.
- Program to compute variance (10/16):
variance.c.
- Program to count different characters (10/18):
countchars.c.
- "Floating point is strange" examples (10/18):
float1.c,
float2.c.
- Program to illustrate using array (10/23):
simple-array.c.
- Simple ASCII-art program (example of using 2D array)
(10/25, briefly):
ascii-art.c.
- Bubble sort of "random" data (10/25):
bubble-sort-vla.c.
- Program to illustrate using array, revised (10/30):
simple-array-v2.c.
- Bubble sort of "random" data, revised (11/01):
bubble-sort-malloc.c.
- Program building 2D array two ways (11/01):
2d-array.c.
- Program to get and echo line of text using fgets() (11/03):
echoline-fgets.c.
- Program to find length of text string, several ways (11/06):
simple-strings.c.
- Program to echo command-line arguments (11/06):
echo-args.c.
- Program to define and test a type for 3D vectors (11/10):
three-d-vectors.h,
test-three-d-vectors.c.
- Program to find difference in days between two dates
(example of using struct (11/13):
date-difference.c.
- Revision of program to sort integers, this time
using qsort (11/15):
use-qsort.c.
- Program to do numerical integration of more than one function
(11/15):
numint.c.
- Makefile example (11/17):
Source code files and Makefiles
here,
or ZIP archive
here.
- Program to summarize grade information (11/20):
grades.c.
- Programs to write, read a binary file (11/20):
write-binfile.c,
read-binfile.c.
- Program to show long in bit form, two ways (11/27):
showlong.c.
- Program to demo bit operations (11/27):
flags.c.
- Sorted linked list (not in class yet):
Source code files and Makefiles
here,
or ZIP archive
here.
Other files